Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check whether paymentunits have deliverunits set before processing #458

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions commcare_connect/form_receiver/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def clean_form_submission(access: OpportunityAccess, user_visit: UserVisit, xfor


def process_deliver_unit(user, xform: XForm, app: CommCareApp, opportunity: Opportunity, deliver_unit_block: dict):
if not opportunity.is_setup_complete:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this to be more targeted? Occasionally projects add new payment units part way through, and I would be concerned that if they improperly add new ones, this check would prevent the old ones from being processed as well. If we instead just did an error message when we hit this error, that might be safer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I am happy to just make a sentry error here instead of hard-fail. Though, per above comment this shouldn't be possible.

raise ProcessingError("Opportunity setup is not complete")
deliver_unit = get_or_create_deliver_unit(app, deliver_unit_block)
access = OpportunityAccess.objects.get(opportunity=opportunity, user=user)
counts = (
Expand Down
3 changes: 3 additions & 0 deletions commcare_connect/opportunity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def is_setup_complete(self):
for pu in self.paymentunit_set.all():
if not (pu.max_total and pu.max_daily):
return False
if not pu.deliver_units.exists():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add this as validation on the form that sets these up? It probably shouldn't be possible to submit that form (or section of the form) if there are none selected. That way users will also know before forms start to come in.

Copy link
Member Author

@sravfeyn sravfeyn Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, the form already has this as required, so this shouldn't really happen, I am not sure how it ended up happening. Do you have any idea how this could have occurred?

# Payment unit must have deliver units configured
return False
return True

@property
Expand Down
Loading