diff --git a/commcare_connect/opportunity/management/commands/auto_approval_opportunities.py b/commcare_connect/opportunity/management/commands/auto_approval_opportunities.py index 1292700c..48002a9e 100644 --- a/commcare_connect/opportunity/management/commands/auto_approval_opportunities.py +++ b/commcare_connect/opportunity/management/commands/auto_approval_opportunities.py @@ -9,20 +9,30 @@ 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" + ) + 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) 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] - ) - update_status(completed_works, access, False) + completed_works = access.completedwork_set.exclude(status__in=excluded) + update_status(completed_works, access, update_payment) self.stdout.write(self.style.SUCCESS(f"Successfully processed opportunity with id {opp}"))