|
|
|
@ -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', 'deleted') |
|
|
|
|
read_only_fields = ('chart', 'price', 'set_price', 'set_date', 'actual_start', 'actual_end', 'deleted') |
|
|
|
|
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') |
|
|
|
|
|
|
|
|
|
def create(self, validated_data): |
|
|
|
|
user = self.context['request'].user |
|
|
|
@ -234,21 +234,46 @@ class CShiftSerializer(ShiftSerializer): |
|
|
|
|
validated_data['price'] = price |
|
|
|
|
return serializers.ModelSerializer.create(self, validated_data) |
|
|
|
|
|
|
|
|
|
def update(self, instance, validated_data): |
|
|
|
|
|
|
|
|
|
if instance.actual_start: |
|
|
|
|
raise serializers.ValidationError("Can't update after check in.") |
|
|
|
|
|
|
|
|
|
# Reset approval on update |
|
|
|
|
instance.approved = None |
|
|
|
|
|
|
|
|
|
return super().update(instance, validated_data) |
|
|
|
|
|
|
|
|
|
class PShiftSerializer(ShiftSerializer): |
|
|
|
|
action = serializers.ChoiceField(write_only=True, choices=['checkin', 'checkout']) |
|
|
|
|
action = serializers.ChoiceField(write_only=True, allow_blank=True, choices=['checkin', 'checkout']) |
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
model = Shift |
|
|
|
|
fields = ('uuid', 'action', 'chart', 'price', 'set_price', 'set_date', 'set_start', 'set_end', 'actual_start', 'actual_end', 'amount', 'description', 'deleted') |
|
|
|
|
fields = ('uuid', 'action', 'chart', 'price', 'set_price', 'set_date', 'set_start', 'set_end', 'actual_start', 'actual_end', 'amount', 'description', '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'] |
|
|
|
|
action = validated_data['action'] |
|
|
|
|
chart = validated_data['chart'] |
|
|
|
|
|
|
|
|
|
if approved == True: |
|
|
|
|
if instance.deleted: |
|
|
|
|
raise serializers.ValidationError("Shift was deleted.") |
|
|
|
|
|
|
|
|
|
instance.approved = True |
|
|
|
|
|
|
|
|
|
elif approved == False: |
|
|
|
|
if instance.actual_start: |
|
|
|
|
raise serializers.ValidationError("Can't disapprove after check in.") |
|
|
|
|
|
|
|
|
|
instance.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 instance.actual_start: |
|
|
|
|
raise serializers.ValidationError("Already checked in.") |
|
|
|
|
if chart: |
|
|
|
|