@@ -518,6 +518,7 @@ def update(self, instance, validated_data):
518518 to = None
519519 if modified_at and instance .modified_at and modified_at < instance .modified_at :
520520 raise serializers .ValidationError ({"modified_at" : settings .DREF_OP_UPDATE_FINAL_REPORT_UPDATE_ERROR_MESSAGE })
521+ validated_data ["modified_at" ] = modified_at
521522 dref = super ().update (instance , validated_data )
522523 if to :
523524 transaction .on_commit (lambda : send_dref_email .delay (dref .id , list (to ), "Updated" ))
@@ -549,7 +550,7 @@ class DrefOperationalUpdateSerializer(NestedUpdateMixin, NestedCreateMixin, Mode
549550
550551 class Meta :
551552 model = DrefOperationalUpdate
552- read_only_fields = ("operational_update_number" ,)
553+ read_only_fields = ("operational_update_number" , "modified_by" , "created_by" )
553554 exclude = ("images" , "photos" , "event_map" , "cover_image" )
554555
555556 def validate (self , data ):
@@ -574,7 +575,7 @@ def validate(self, data):
574575 return data
575576
576577 def validate_appeal_code (self , appeal_code ):
577- if appeal_code != self .instance .appeal_code :
578+ if appeal_code and appeal_code != self .instance .appeal_code :
578579 raise serializers .ValidationError ("Can't edit MDR Code" )
579580 return appeal_code
580581
@@ -590,6 +591,7 @@ def create(self, validated_data):
590591 dref_operational_update = (
591592 DrefOperationalUpdate .objects .filter (dref = dref ).order_by ("-operational_update_number" ).first ()
592593 )
594+ validated_data ["created_by" ] = self .context ["request" ].user
593595 if not dref_operational_update :
594596 validated_data ["title" ] = dref .title
595597 validated_data ["title_prefix" ] = dref .title_prefix
@@ -807,7 +809,7 @@ def create(self, validated_data):
807809 return operational_update
808810
809811 def update (self , instance , validated_data ):
810- validated_data ["updated_by " ] = self .context ["request" ].user
812+ validated_data ["modified_by " ] = self .context ["request" ].user
811813 # changing_timeframe_operation = validated_data.get(
812814 # "changing_timeframe_operation", instance.changing_timeframe_operation
813815 # )
@@ -887,6 +889,7 @@ def update(self, instance, validated_data):
887889
888890 if modified_at and instance .modified_at and modified_at < instance .modified_at :
889891 raise serializers .ValidationError ({"modified_at" : settings .DREF_OP_UPDATE_FINAL_REPORT_UPDATE_ERROR_MESSAGE })
892+ validated_data ["modified_at" ] = modified_at
890893 return super ().update (instance , validated_data )
891894
892895
@@ -911,9 +914,11 @@ class DrefFinalReportSerializer(NestedUpdateMixin, NestedCreateMixin, ModelSeria
911914 financial_report_details = DrefFileSerializer (source = "financial_report" , read_only = True )
912915 created_by_details = UserNameSerializer (source = "created_by" , read_only = True )
913916 users_details = UserNameSerializer (source = "users" , many = True , read_only = True )
917+ modified_by_details = UserNameSerializer (source = "modified_by" , read_only = True )
914918
915919 class Meta :
916920 model = DrefFinalReport
921+ read_only_fields = ("modified_by" , "created_by" , "financial_report_preview" )
917922 exclude = (
918923 "images" ,
919924 "photos" ,
@@ -955,6 +960,7 @@ def create(self, validated_data):
955960 dref_operational_update = (
956961 DrefOperationalUpdate .objects .filter (dref = dref , is_published = True ).order_by ("-operational_update_number" ).first ()
957962 )
963+ validated_data ["created_by" ] = self .context ["request" ].user
958964 if dref_operational_update :
959965 validated_data ["title" ] = dref_operational_update .title
960966 validated_data ["title_prefix" ] = dref_operational_update .title_prefix
@@ -1150,8 +1156,8 @@ def update(self, instance, validated_data):
11501156 raise serializers .ValidationError ({"modified_at" : "Modified At is required!" })
11511157 if modified_at and instance .modified_at and modified_at < instance .modified_at :
11521158 raise serializers .ValidationError ({"modified_at" : settings .DREF_OP_UPDATE_FINAL_REPORT_UPDATE_ERROR_MESSAGE })
1153-
1154- validated_data ["updated_by " ] = self .context ["request" ].user
1159+ validated_data [ "modified_at" ] = modified_at
1160+ validated_data ["modified_by " ] = self .context ["request" ].user
11551161 return super ().update (instance , validated_data )
11561162
11571163
0 commit comments