Skip to content

Commit

Permalink
refactor: create advance ledger entries on submit and cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthra-kumar committed Oct 31, 2024
1 parent f176a82 commit 575ca5b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def on_submit(self):
self.update_outstanding_amounts()
self.update_payment_schedule()
self.update_payment_requests()
self.make_advance_payment_ledger_entries()
self.update_advance_paid() # advance_paid_status depends on the payment request amount
self.set_status()

Expand Down Expand Up @@ -279,6 +280,7 @@ def on_cancel(self):
self.delink_advance_entry_references()
self.update_payment_schedule(cancel=1)
self.update_payment_requests(cancel=True)
self.make_advance_payment_ledger_entries()
self.update_advance_paid() # advance_paid_status depends on the payment request amount
self.set_status()

Expand Down Expand Up @@ -1951,6 +1953,26 @@ def _allocation_to_unset_pr_row(
allocated_negative_outstanding,
)

def make_advance_payment_ledger_entries(self):
if self.docstatus == 1 or self.docstatus == 2:
advance_payment_doctypes = frappe.get_hooks(
"advance_payment_receivable_doctypes"
) + frappe.get_hooks("advance_payment_payable_doctypes")

advance_doctype_references = [
x for x in self.references if x.reference_doctype in advance_payment_doctypes
]
for x in advance_doctype_references:
doc = frappe.new_doc("Advance Payment Ledger Entry")
doc.company = self.company
doc.voucher_type = self.doctype
doc.voucher_no = self.name
doc.against_voucher_type = x.reference_doctype
doc.against_voucher_no = x.reference_name
doc.amount = x.allocated_amount if self.docstatus == 1 else -1 * x.allocated_amount
doc.event = "Submit" if self.docstatus == 1 else "Cancel"
doc.save()

@frappe.whitelist()
def set_matched_payment_requests(self, matched_payment_requests):
"""
Expand Down

0 comments on commit 575ca5b

Please sign in to comment.