refactor: create advance ledger entries on submit and cancel

This commit is contained in:
ruthra kumar
2024-10-16 17:16:31 +05:30
parent f176a82198
commit 575ca5b900

View File

@@ -192,6 +192,7 @@ class PaymentEntry(AccountsController):
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()
@@ -279,6 +280,7 @@ class PaymentEntry(AccountsController):
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()
@@ -1951,6 +1953,26 @@ class PaymentEntry(AccountsController):
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):
"""