Skip to content

Commit 8ff6b99

Browse files
committed
add ApprovalProcessSerializer
1 parent c684b34 commit 8ff6b99

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/hct_mis_api/apps/payment/api/serializers.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
)
1818
from hct_mis_api.apps.household.models import Household, Individual
1919
from hct_mis_api.apps.payment.models import (
20+
Approval,
21+
ApprovalProcess,
2022
DeliveryMechanismPerPaymentPlan,
2123
FinancialServiceProvider,
2224
Payment,
@@ -161,6 +163,64 @@ class Meta:
161163
)
162164

163165

166+
class ApprovalSerializer(serializers.ModelSerializer):
167+
created_by = serializers.SerializerMethodField()
168+
169+
class Meta:
170+
model = Approval
171+
fields = (
172+
"type",
173+
"comment",
174+
"created_by",
175+
)
176+
177+
def get_created_by(self, obj: PaymentPlan) -> str:
178+
return f"{obj.created_by.first_name} {obj.created_by.last_name}" if obj.created_by else ""
179+
180+
181+
class ApprovalProcessSerializer(serializers.ModelSerializer):
182+
approvals = ApprovalSerializer(many=True, read_only=True)
183+
sent_for_approval_by = serializers.SerializerMethodField()
184+
sent_for_finance_release_by = serializers.SerializerMethodField()
185+
sent_for_authorization_by = serializers.SerializerMethodField()
186+
187+
class Meta:
188+
model = ApprovalProcess
189+
fields = (
190+
"approvals",
191+
"sent_for_approval_by",
192+
"sent_for_authorization_by",
193+
"sent_for_finance_release_by",
194+
"sent_for_approval_date",
195+
"sent_for_authorization_date",
196+
"sent_for_finance_release_date",
197+
"approval_number_required",
198+
"authorization_number_required",
199+
"finance_release_number_required",
200+
)
201+
202+
def get_sent_for_approval_by(self, obj: PaymentPlan) -> str:
203+
return (
204+
f"{obj.sent_for_approval_by.first_name} {obj.sent_for_approval_by.last_name}"
205+
if obj.sent_for_approval_by
206+
else ""
207+
)
208+
209+
def get_sent_for_authorization_by(self, obj: PaymentPlan) -> str:
210+
return (
211+
f"{obj.sent_for_authorization_by.first_name} {obj.sent_for_authorization_by.last_name}"
212+
if obj.sent_for_authorization_by
213+
else ""
214+
)
215+
216+
def get_sent_for_finance_release_by(self, obj: PaymentPlan) -> str:
217+
return (
218+
f"{obj.sent_for_finance_release_by.first_name} {obj.sent_for_finance_release_by.last_name}"
219+
if obj.sent_for_finance_release_by
220+
else ""
221+
)
222+
223+
164224
class DeliveryMechanismPerPaymentPlanSerializer(serializers.ModelSerializer):
165225
name = serializers.CharField(source="delivery_mechanism.name")
166226
code = serializers.CharField(source="delivery_mechanism.code")
@@ -254,6 +314,7 @@ class PaymentPlanDetailSerializer(AdminUrlSerializerMixin, PaymentPlanListSerial
254314
can_download_xlsx = serializers.SerializerMethodField()
255315
can_send_xlsx_password = serializers.SerializerMethodField()
256316
split_choices = serializers.SerializerMethodField()
317+
approval_process = ApprovalProcessSerializer(read_only=True, many=True)
257318

258319
class Meta(PaymentPlanListSerializer.Meta):
259320
fields = PaymentPlanListSerializer.Meta.fields + ( # type: ignore
@@ -287,6 +348,11 @@ class Meta(PaymentPlanListSerializer.Meta):
287348
"can_export_xlsx",
288349
"can_download_xlsx",
289350
"can_send_xlsx_password",
351+
"approval_process",
352+
"total_entitled_quantity_usd",
353+
"total_entitled_quantity_revised_usd",
354+
"total_delivered_quantity_usd",
355+
"total_undelivered_quantity_usd",
290356
)
291357

292358
@staticmethod

0 commit comments

Comments
 (0)