Skip to content

Commit

Permalink
Merge pull request #451 from dimagi/pkv/fix-approve-visit-causes-review
Browse files Browse the repository at this point in the history
Fix Review creation for Already Approved Visits.
  • Loading branch information
pxwxnvermx authored Dec 11, 2024
2 parents 061ad22 + d04163e commit afea4f6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions commcare_connect/opportunity/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,16 +867,18 @@ def visit_verification(request, org_slug=None, pk=None):
@org_member_required
def approve_visit(request, org_slug=None, pk=None):
user_visit = UserVisit.objects.get(pk=pk)
user_visit.status = VisitValidationStatus.approved
if user_visit.opportunity.managed:
user_visit.review_created_on = now()
user_visit.save()
opp_id = user_visit.opportunity_id
access = OpportunityAccess.objects.get(user_id=user_visit.user_id, opportunity_id=opp_id)
update_payment_accrued(opportunity=access.opportunity, users=[access.user])
if user_visit.status != VisitValidationStatus.approved:
user_visit.status = VisitValidationStatus.approved
if user_visit.opportunity.managed:
user_visit.review_created_on = now()
user_visit.save()
update_payment_accrued(opportunity=user_visit.opportunity, users=[user_visit.user])
if user_visit.opportunity.managed:
return redirect("opportunity:user_visit_review", org_slug, opp_id)
return redirect("opportunity:user_visits_list", org_slug=org_slug, opp_id=user_visit.opportunity.id, pk=access.id)
return redirect(
"opportunity:user_visits_list", org_slug=org_slug, opp_id=opp_id, pk=user_visit.opportunity_access_id
)


@org_member_required
Expand Down

0 comments on commit afea4f6

Please sign in to comment.