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

fix(Treatment Counselling): Add payment entry on_cancel and paid amount calculation #514

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading