diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 00d1844a3e7..5f56743167d 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -25,6 +25,10 @@ from erpnext.accounts.doctype.invoice_discounting.invoice_discounting import ( get_party_account_based_on_invoice_discounting, ) from erpnext.accounts.doctype.journal_entry.journal_entry import get_default_bank_cash_account +from erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger import ( + validate_docs_for_deferred_accounting, + validate_docs_for_voucher_types, +) from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category import ( get_party_tax_withholding_details, ) @@ -203,6 +207,23 @@ class PaymentEntry(AccountsController): self.update_advance_paid() # advance_paid_status depends on the payment request amount self.set_status() + def validate_for_repost(self): + validate_docs_for_voucher_types(["Payment Entry"]) + validate_docs_for_deferred_accounting([self.name], []) + + def on_update_after_submit(self): + # Flag will be set on Reconciliation + # Reconciliation tool will anyways repost ledger entries. So, no need to check and do implicit repost. + if self.flags.get("ignore_reposting_on_reconciliation"): + return + + self.needs_repost = self.check_if_fields_updated( + fields_to_check=[], child_tables={"references": [], "taxes": [], "deductions": []} + ) + if self.needs_repost: + self.validate_for_repost() + self.repost_accounting_entries() + def set_liability_account(self): # Auto setting liability account should only be done during 'draft' status if self.docstatus > 0 or self.payment_type == "Internal Transfer": diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 9678b001f16..eb11168562e 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -795,6 +795,8 @@ def update_reference_in_payment_entry( frappe._dict({"difference_posting_date": d.difference_posting_date}), dimensions_dict ) + # Ledgers will be reposted by Reconciliation tool + payment_entry.flags.ignore_reposting_on_reconciliation = True if not do_not_save: payment_entry.save(ignore_permissions=True) return row, update_advance_paid