|
17 | 17 | )
|
18 | 18 | from hct_mis_api.apps.household.models import Household, Individual
|
19 | 19 | from hct_mis_api.apps.payment.models import (
|
| 20 | + Approval, |
| 21 | + ApprovalProcess, |
20 | 22 | DeliveryMechanismPerPaymentPlan,
|
21 | 23 | FinancialServiceProvider,
|
22 | 24 | Payment,
|
@@ -161,6 +163,64 @@ class Meta:
|
161 | 163 | )
|
162 | 164 |
|
163 | 165 |
|
| 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 | + |
164 | 224 | class DeliveryMechanismPerPaymentPlanSerializer(serializers.ModelSerializer):
|
165 | 225 | name = serializers.CharField(source="delivery_mechanism.name")
|
166 | 226 | code = serializers.CharField(source="delivery_mechanism.code")
|
@@ -254,6 +314,7 @@ class PaymentPlanDetailSerializer(AdminUrlSerializerMixin, PaymentPlanListSerial
|
254 | 314 | can_download_xlsx = serializers.SerializerMethodField()
|
255 | 315 | can_send_xlsx_password = serializers.SerializerMethodField()
|
256 | 316 | split_choices = serializers.SerializerMethodField()
|
| 317 | + approval_process = ApprovalProcessSerializer(read_only=True, many=True) |
257 | 318 |
|
258 | 319 | class Meta(PaymentPlanListSerializer.Meta):
|
259 | 320 | fields = PaymentPlanListSerializer.Meta.fields + ( # type: ignore
|
@@ -287,6 +348,11 @@ class Meta(PaymentPlanListSerializer.Meta):
|
287 | 348 | "can_export_xlsx",
|
288 | 349 | "can_download_xlsx",
|
289 | 350 | "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", |
290 | 356 | )
|
291 | 357 |
|
292 | 358 | @staticmethod
|
|
0 commit comments