From 5b48ce157dae7f002b90370c92a482bd026c4a30 Mon Sep 17 00:00:00 2001 From: Cal Ellowitz Date: Thu, 5 Dec 2024 22:15:08 -0500 Subject: [PATCH 1/2] add option to include over limit works --- .../commands/auto_approval_opportunities.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/commcare_connect/opportunity/management/commands/auto_approval_opportunities.py b/commcare_connect/opportunity/management/commands/auto_approval_opportunities.py index 1292700c..d4d9448c 100644 --- a/commcare_connect/opportunity/management/commands/auto_approval_opportunities.py +++ b/commcare_connect/opportunity/management/commands/auto_approval_opportunities.py @@ -9,19 +9,27 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument( - "--opp", type=int, required=True, help="ID of the opportunity to run auto-approval logic on" + "--opp", + type=int, + required=True, + help="ID of the opportunity to run auto-approval logic on", + ) + parser.add_argument( + "--include-over-limit", action="store_true", help="Also run auto-approval logic on over limit works" ) def handle(self, *args, opp: int, **options): + include_over_limit = options.get("include_over_limit", False) + excluded = [CompletedWorkStatus.rejected] + if not include_over_limit: + excluded.append(CompletedWorkStatus.over_limit) try: opportunity = Opportunity.objects.get(id=opp) access_objects = OpportunityAccess.objects.filter( opportunity=opportunity, suspended=False, opportunity__auto_approve_payments=True ) for access in access_objects: - completed_works = access.completedwork_set.exclude( - status__in=[CompletedWorkStatus.rejected, CompletedWorkStatus.over_limit] - ) + completed_works = access.completedwork_set.exclude(status__in=excluded) update_status(completed_works, access, False) self.stdout.write(self.style.SUCCESS(f"Successfully processed opportunity with id {opp}")) From 8314a3a61612bd137230c9127eaae5dcd2e7f464 Mon Sep 17 00:00:00 2001 From: Cal Ellowitz Date: Thu, 5 Dec 2024 22:25:58 -0500 Subject: [PATCH 2/2] add arg to update payment --- .../management/commands/auto_approval_opportunities.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commcare_connect/opportunity/management/commands/auto_approval_opportunities.py b/commcare_connect/opportunity/management/commands/auto_approval_opportunities.py index d4d9448c..48002a9e 100644 --- a/commcare_connect/opportunity/management/commands/auto_approval_opportunities.py +++ b/commcare_connect/opportunity/management/commands/auto_approval_opportunities.py @@ -17,9 +17,11 @@ def add_arguments(self, parser): parser.add_argument( "--include-over-limit", action="store_true", help="Also run auto-approval logic on over limit works" ) + parser.add_argument("--update-payment", action="store_true", help="Update payment accrued") def handle(self, *args, opp: int, **options): include_over_limit = options.get("include_over_limit", False) + update_payment = options.get("update_payment", False) excluded = [CompletedWorkStatus.rejected] if not include_over_limit: excluded.append(CompletedWorkStatus.over_limit) @@ -30,7 +32,7 @@ def handle(self, *args, opp: int, **options): ) for access in access_objects: completed_works = access.completedwork_set.exclude(status__in=excluded) - update_status(completed_works, access, False) + update_status(completed_works, access, update_payment) self.stdout.write(self.style.SUCCESS(f"Successfully processed opportunity with id {opp}"))