Skip to content

Commit

Permalink
Update iaso/api/payments/serializers.py
Browse files Browse the repository at this point in the history
Co-authored-by: hakifran <[email protected]>
  • Loading branch information
quang-le and hakifran authored Nov 29, 2024
1 parent b315a42 commit 3b62041
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions iaso/api/payments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ def get_can_see_change_requests(self, obj):
user = self.context.get("request").user
if user.is_superuser:
return True
user_org_units = sorted(list(user.iaso_profile.get_hierarchy_for_user().values_list("id", flat=True)))
change_requests_org_units_for_lot = sorted(
list(OrgUnitChangeRequest.objects.filter(payment__in=obj.payments.all()).values_list("org_unit__id"))
user_org_units = set(user.iaso_profile.get_hierarchy_for_user().values_list("id", flat=True))
change_requests_org_units_for_lot = (
OrgUnitChangeRequest.objects.filter(payment__in=obj.payments.all())
.values_list("org_unit__id", flat=True)
.distinct()
)
return user_org_units == change_requests_org_units_for_lot
return set(change_requests_org_units_for_lot).issubset(user_org_units)

def get_payments(self, obj):
payments = obj.payments.all()
Expand Down

0 comments on commit 3b62041

Please sign in to comment.