From 55abba460d303978ef383a6661f9449343ffa8d5 Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Mon, 3 Jun 2024 10:31:34 +0200 Subject: [PATCH 1/2] fix: Correct advance amount after payment cancellation --- erpnext/controllers/accounts_controller.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 88f0ae4a6f..3d39760973 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1968,7 +1968,9 @@ class AccountsController(TransactionBase): .select(si.name) .left_join(sii) .on(sii.parent == si.name) - .where((si.is_down_payment_invoice == 1) & (sii.sales_order == self.name)) + .where( + (si.is_down_payment_invoice == 1) & (sii.sales_order == self.name) & (si.docstatus == 1) + ) .run(as_list=True) ) -- GitLab From e2549291c42c94b13b6274eec2c5806de555543a Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Mon, 3 Jun 2024 16:26:41 +0200 Subject: [PATCH 2/2] fix: update advance amount from down payment paid via a journal entry --- .../doctype/journal_entry/journal_entry.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 1e772f47d9..12b0d56d42 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -198,7 +198,7 @@ class JournalEntry(AccountsController): self.update_asset_value() self.update_inter_company_jv() self.update_invoice_discounting() - self.update_unreconciled_amount() # @dokos + self.update_unreconciled_amount() # @dokos self.update_booked_depreciation() def on_update_after_submit(self): @@ -248,6 +248,20 @@ class JournalEntry(AccountsController): if d.reference_type in advance_payment_doctypes: advance_paid.setdefault(d.reference_type, []).append(d.reference_name) + # @dokos + if d.reference_name and d.reference_type == "Sales Invoice": # @dokos + for so in frappe.get_all( + "Sales Invoice Item", + filters={ + "parenttype": "Sales Invoice", + "parent": d.reference_name, + "sales_order": ("is", "set"), + }, + pluck="sales_order", + ): + frappe.get_doc("Sales Order", so, for_update=True).set_total_advance_paid() + # @dokos + for voucher_type, order_list in advance_paid.items(): for voucher_no in list(set(order_list)): frappe.get_doc(voucher_type, voucher_no).set_total_advance_paid() -- GitLab