Skip to content

Commit

Permalink
fix(Treatment Counselling): Add payment entry on_cancel and paid amou…
Browse files Browse the repository at this point in the history
…nt calculation
  • Loading branch information
Sajinsr committed Oct 22, 2024
1 parent b972c57 commit 743425e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
22 changes: 16 additions & 6 deletions healthcare/healthcare/custom_doctype/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@
@frappe.whitelist()
def set_paid_amount_in_treatment_counselling(doc, method):
if doc.treatment_counselling and doc.paid_amount:
treatment_counselling_doc = frappe.get_doc("Treatment Counselling", doc.treatment_counselling)
treatment_counselling_doc.paid_amount = doc.paid_amount
treatment_counselling_doc.outstanding_amount = (
treatment_counselling_doc.amount - treatment_counselling_doc.paid_amount
)
treatment_counselling_doc.save()
on_cancel = True if method == "on_cancel" else False
validate_treatment_counselling(doc, on_cancel)


def validate_treatment_counselling(doc, on_cancel=False):
treatment_counselling_doc = frappe.get_doc("Treatment Counselling", doc.treatment_counselling)

paid_amount = treatment_counselling_doc.paid_amount + doc.paid_amount
if on_cancel:
paid_amount = treatment_counselling_doc.paid_amount - doc.paid_amount

treatment_counselling_doc.paid_amount = paid_amount
treatment_counselling_doc.outstanding_amount = (
treatment_counselling_doc.amount - treatment_counselling_doc.paid_amount
)
treatment_counselling_doc.save()
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,20 @@ def set_treatment_plan_template_items(doc):
if su_item and su_rate:
doc.append(
"treatment_plan_template_items",
{"type": "Item", "template": su_item, "qty": doc.expected_length_of_stay, "amount": su_rate},
{
"type": "Item",
"template": su_item,
"qty": (doc.expected_length_of_stay or 1),
"amount": su_rate,
},
)


def set_total_amount(doc):
total_price = 0
for item in doc.treatment_plan_template_items:
if item.amount:
total_price += item.amount
total_price += item.qty * item.amount

doc.amount = total_price

Expand All @@ -164,11 +169,6 @@ def create_ip_from_treatment_counselling(admission_order, treatment_counselling)

@frappe.whitelist()
def create_payment_entry(treatment_counselling):
payment_entry = frappe.db.exists(
"Payment Entry", {"treatment_counselling": treatment_counselling, "docstatus": ["!=", 2]}
)
if payment_entry:
return payment_entry
treatment_counselling_doc = frappe.get_doc("Treatment Counselling", treatment_counselling)
payment_entry_doc = frappe.new_doc("Payment Entry")
payment_entry_doc.update(
Expand Down
3 changes: 2 additions & 1 deletion healthcare/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
"after_insert": "healthcare.regional.india.abdm.utils.set_consent_attachment_details"
},
"Payment Entry": {
"on_submit": "healthcare.healthcare.custom_doctype.payment_entry.set_paid_amount_in_treatment_counselling"
"on_submit": "healthcare.healthcare.custom_doctype.payment_entry.set_paid_amount_in_treatment_counselling",
"on_cancel": "healthcare.healthcare.custom_doctype.payment_entry.set_paid_amount_in_treatment_counselling",
},
}

Expand Down

0 comments on commit 743425e

Please # to comment.