Rename shift's approved to provider_approved
This commit is contained in:
parent
f34115736b
commit
967a061d3d
20
caremyway/api/migrations/0003_auto_20180622_0338.py
Normal file
20
caremyway/api/migrations/0003_auto_20180622_0338.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.1 on 2018-06-22 03:38
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0002_shift_approved'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='shift',
|
||||
old_name='approved',
|
||||
new_name='provider_approved',
|
||||
),
|
||||
]
|
|
@ -65,5 +65,5 @@ class Shift(models.Model):
|
|||
actual_end = models.DateTimeField(null=True)
|
||||
description = models.CharField(max_length=100, null=True)
|
||||
chart = models.TextField(max_length=1000, null=True)
|
||||
approved = models.NullBooleanField(blank=True)
|
||||
provider_approved = models.NullBooleanField(blank=True)
|
||||
deleted = models.BooleanField(default=False)
|
||||
|
|
|
@ -196,8 +196,8 @@ class CShiftSerializer(ShiftSerializer):
|
|||
|
||||
class Meta:
|
||||
model = Shift
|
||||
fields = ('uuid', 'chart', 'get_price_uuid', 'price', 'set_price', 'set_date', 'set_start', 'set_end', 'actual_start', 'actual_end', 'amount', 'description', 'approved', 'deleted')
|
||||
read_only_fields = ('chart', 'price', 'set_price', 'set_date', 'actual_start', 'actual_end', 'approved', 'deleted')
|
||||
fields = ('uuid', 'chart', 'get_price_uuid', 'price', 'set_price', 'set_date', 'set_start', 'set_end', 'actual_start', 'actual_end', 'amount', 'description', 'provider_approved', 'deleted')
|
||||
read_only_fields = ('chart', 'price', 'set_price', 'set_date', 'actual_start', 'actual_end', 'provider_approved', 'deleted')
|
||||
|
||||
def create(self, validated_data):
|
||||
user = self.context['request'].user
|
||||
|
@ -240,7 +240,7 @@ class CShiftSerializer(ShiftSerializer):
|
|||
raise serializers.ValidationError("Can't update after check in.")
|
||||
|
||||
# Reset approval on update
|
||||
instance.approved = None
|
||||
instance.provider_approved = None
|
||||
|
||||
return super().update(instance, validated_data)
|
||||
|
||||
|
@ -249,31 +249,31 @@ class PShiftSerializer(ShiftSerializer):
|
|||
|
||||
class Meta:
|
||||
model = Shift
|
||||
fields = ('uuid', 'action', 'chart', 'price', 'set_price', 'set_date', 'set_start', 'set_end', 'actual_start', 'actual_end', 'amount', 'description', 'approved', 'deleted')
|
||||
fields = ('uuid', 'action', 'chart', 'price', 'set_price', 'set_date', 'set_start', 'set_end', 'actual_start', 'actual_end', 'amount', 'description', 'provider_approved', 'deleted')
|
||||
read_only_fields = ('uuid', 'price', 'set_price', 'set_date', 'set_start', 'set_end', 'actual_start', 'actual_end', 'description', 'deleted')
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
approved = validated_data['approved']
|
||||
provider_approved = validated_data['provider_approved']
|
||||
action = validated_data['action']
|
||||
chart = validated_data['chart']
|
||||
|
||||
if approved == True:
|
||||
if provider_approved == True:
|
||||
if instance.deleted:
|
||||
raise serializers.ValidationError("Shift was deleted.")
|
||||
|
||||
instance.approved = True
|
||||
instance.provider_approved = True
|
||||
|
||||
elif approved == False:
|
||||
elif provider_approved == False:
|
||||
if instance.actual_start:
|
||||
raise serializers.ValidationError("Can't disapprove after check in.")
|
||||
|
||||
instance.approved = False
|
||||
instance.provider_approved = False
|
||||
|
||||
if action == 'checkin':
|
||||
if instance.deleted:
|
||||
raise serializers.ValidationError("Shift was deleted.")
|
||||
if not instance.approved:
|
||||
raise serializers.ValidationError("Shift hasn't been approved.")
|
||||
if not instance.provider_approved:
|
||||
raise serializers.ValidationError("Shift hasn't been approved by the provider..")
|
||||
if instance.actual_start:
|
||||
raise serializers.ValidationError("Already checked in.")
|
||||
if chart:
|
||||
|
|
|
@ -120,7 +120,7 @@ def shift_filter(get_self):
|
|||
user = get_self.request.user
|
||||
qp = get_self.request.query_params
|
||||
completed = validate_param(qp.get('completed', 'unspecified'), serializers.BooleanField())
|
||||
approved = validate_param(qp.get('approved', 'unspecified'), serializers.NullBooleanField())
|
||||
provider_approved = validate_param(qp.get('provider_approved', 'unspecified'), serializers.NullBooleanField())
|
||||
manage = validate_param(qp.get('manage'), serializers.UUIDField(allow_null=True))
|
||||
work_type = validate_param(qp.get('work_type'), serializers.UUIDField(allow_null=True))
|
||||
|
||||
|
@ -128,11 +128,11 @@ def shift_filter(get_self):
|
|||
.filter(
|
||||
Q(price__management__client__user__username=user)
|
||||
| Q(price__management__provider__user__username=user)) \
|
||||
.order_by('approved', 'set_start')
|
||||
.order_by('provider_approved', 'set_start')
|
||||
if completed is not 'unspecified':
|
||||
shifts = shifts.exclude(actual_end__isnull=completed)
|
||||
if approved is not 'unspecified':
|
||||
shifts = shifts.filter(approved=approved)
|
||||
if provider_approved is not 'unspecified':
|
||||
shifts = shifts.filter(provider_approved=provider_approved)
|
||||
if manage:
|
||||
shifts = shifts.filter(price__management__uuid=manage)
|
||||
if work_type:
|
||||
|
|
Loading…
Reference in New Issue
Block a user