diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 1e772f47d996ca048469de106f1951400754cab2..12b0d56d4237a7ba79402bf2a067f3ea3c78dcbe 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() diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 88f0ae4a6ffec0c127da1c3be61de85b09d3b7e7..3d397609733c08a861d219c5d070f2c26c66b68d 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) )