Skip to content

Commit

Permalink
return user of the approval process as defined str representation ins…
Browse files Browse the repository at this point in the history
…tead of username
  • Loading branch information
pkujawa committed Apr 3, 2024
1 parent e61ed64 commit 7a4a613
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions backend/hct_mis_api/apps/payment/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from rest_framework import serializers

from hct_mis_api.apps.account.api.fields import Base64ModelField
Expand All @@ -21,6 +23,7 @@ class PaymentPlanSerializer(serializers.ModelSerializer):
follow_ups = FollowUpPaymentPlanSerializer(many=True, read_only=True)
program = serializers.CharField(source="program.name")
program_id = Base64ModelField(model_name="Program")
last_approval_process_by = serializers.SerializerMethodField()

class Meta:
model = PaymentPlan
Expand All @@ -45,6 +48,9 @@ class Meta:
"last_approval_process_by",
)

def get_last_approval_process_by(self, obj: PaymentPlan) -> Optional[str]:
return str(obj.last_approval_process_by) if obj.last_approval_process_by else None


class PaymentPlanBulkActionSerializer(serializers.Serializer):
ids = serializers.ListField(child=serializers.CharField())
Expand Down
6 changes: 3 additions & 3 deletions backend/hct_mis_api/apps/payment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,13 +1022,13 @@ def _get_last_approval_process_data(self) -> dict:
if self.status == PaymentPlan.Status.IN_APPROVAL:
return {
"modified_date": approval_process.sent_for_approval_date,
"modified_by": approval_process.sent_for_approval_by.username,
"modified_by": approval_process.sent_for_approval_by,
}
if self.status == PaymentPlan.Status.IN_AUTHORIZATION:
if approval := approval_process.approvals.filter(type=Approval.APPROVAL).order_by("created_at").last():
return {
"modified_date": approval.created_at,
"modified_by": approval.created_by.username,
"modified_by": approval.created_by,
}
if self.status == PaymentPlan.Status.IN_REVIEW:
if (
Expand All @@ -1038,7 +1038,7 @@ def _get_last_approval_process_data(self) -> dict:
):
return {
"modified_date": approval.created_at,
"modified_by": approval.created_by.username,
"modified_by": approval.created_by,
}
return {
"modified_date": self.updated_at,
Expand Down
6 changes: 3 additions & 3 deletions backend/tests/apps/payments/test_payment_plan_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_list_payment_plans_approval_process_data(
assert response_json[0]["last_approval_process_date"] == approval_process.sent_for_approval_date.strftime(
"%Y-%m-%dT%H:%M:%SZ"
)
assert response_json[0]["last_approval_process_by"] == approval_process.sent_for_approval_by.username
assert response_json[0]["last_approval_process_by"] == str(approval_process.sent_for_approval_by)

self.payment_plan1.status = PaymentPlan.Status.IN_AUTHORIZATION
self.payment_plan1.save()
Expand All @@ -154,7 +154,7 @@ def test_list_payment_plans_approval_process_data(
assert response_json[0]["last_approval_process_date"] == approval_approval.created_at.strftime(
"%Y-%m-%dT%H:%M:%S.%fZ"
)
assert response_json[0]["last_approval_process_by"] == approval_approval.created_by.username
assert response_json[0]["last_approval_process_by"] == str(approval_approval.created_by)

self.payment_plan1.status = PaymentPlan.Status.IN_REVIEW
self.payment_plan1.save()
Expand All @@ -165,7 +165,7 @@ def test_list_payment_plans_approval_process_data(
assert response_json[0]["last_approval_process_date"] == approval_authorization.created_at.strftime(
"%Y-%m-%dT%H:%M:%S.%fZ"
)
assert response_json[0]["last_approval_process_by"] == approval_authorization.created_by.username
assert response_json[0]["last_approval_process_by"] == str(approval_authorization.created_by)

def _bulk_approve_action_response(self) -> Any:
ApprovalProcessFactory(payment_plan=self.payment_plan1)
Expand Down

0 comments on commit 7a4a613

Please sign in to comment.