Skip to content

Commit

Permalink
Merge pull request #448 from dimagi/ce/auto-overlimit
Browse files Browse the repository at this point in the history
add option to include over limit works
  • Loading branch information
pxwxnvermx authored Dec 6, 2024
2 parents cca3df0 + 8314a3a commit 6172ff7
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}"))

Expand Down

0 comments on commit 6172ff7

Please sign in to comment.