From 442e3f2aa271454ff6b6001bc773df86196b0880 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Fri, 16 Jun 2023 13:38:47 +0530 Subject: [PATCH] fix: update outstanding amount and unpaid status on cancellation of payment entry --- .../doctype/payment_entry/payment_entry.py | 25 ++++++++-------- erpnext/accounts/general_ledger.py | 1 + erpnext/accounts/utils.py | 2 +- erpnext/controllers/accounts_controller.py | 29 +++++++------------ erpnext/setup/doctype/company/company.json | 15 +++++----- 5 files changed, 33 insertions(+), 39 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 40dcc8cc680..d901faaed3e 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -872,7 +872,7 @@ class PaymentEntry(AccountsController): self.set("remarks", "\n".join(remarks)) - def build_gl_map(self, is_reconcile=False): + def build_gl_map(self, is_reconcile=True): if self.payment_type in ("Receive", "Pay") and not self.get("party_account_field"): self.setup_party_account_field() @@ -918,16 +918,15 @@ class PaymentEntry(AccountsController): if ( d.reference_doctype in ["Sales Invoice", "Purchase Invoice"] and book_advance_payments_as_liability - and is_advance + and (is_advance or is_reconcile) ): - if not is_reconcile: - self.make_invoice_liability_entry(gl_entries, d) - gle.update( - { - "against_voucher_type": "Payment Entry", - "against_voucher": self.name, - } - ) + self.make_invoice_liability_entry(gl_entries, d) + gle.update( + { + "against_voucher_type": "Payment Entry", + "against_voucher": self.name, + } + ) allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d) gle.update( @@ -939,8 +938,8 @@ class PaymentEntry(AccountsController): if not gle.get("against_voucher_type"): gle.update( { - "against_voucher_type": d.reference_doctype, - "against_voucher": d.reference_name, + "against_voucher_type": d.reference_doctype if is_advance else "Payment Entry", + "against_voucher": d.reference_name if is_advance else self.name, } ) gl_entries.append(gle) @@ -954,6 +953,8 @@ class PaymentEntry(AccountsController): { dr_or_cr + "_in_account_currency": self.unallocated_amount, dr_or_cr: base_unallocated_amount, + "against_voucher_type": "Payment Entry", + "against_voucher": self.name, } ) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index a929ff17b09..a0954a955a0 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -223,6 +223,7 @@ def check_if_in_list(gle, gl_map, dimensions=None): "party_type", "project", "finance_book", + "voucher_no", ] if dimensions: diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index abf9b5e9b2a..e69dcd4199e 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -437,7 +437,7 @@ def add_cc(args=None): def reconcile_against_document( - args, skip_ref_details_update_for_pe=False, is_reconcile=False + args, skip_ref_details_update_for_pe=False, is_reconcile=True ): # nosemgrep """ Cancel PE or JV, Update against document, split if required and resubmit diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 578b26a2cde..f564840251b 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1021,7 +1021,7 @@ class AccountsController(TransactionBase): ) ) - def update_against_document_in_jv(self): + def update_against_document_in_jv(self, is_reconcile=True): """ Links invoice and advance voucher: 1. cancel advance voucher @@ -1078,7 +1078,7 @@ class AccountsController(TransactionBase): if lst: from erpnext.accounts.utils import reconcile_against_document - reconcile_against_document(lst, is_reconcile=True) + reconcile_against_document(lst, is_reconcile) def on_cancel(self): from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries @@ -2919,7 +2919,6 @@ def make_advance_liability_entry( rev = "credit" against = invoice.debit_to party = invoice.customer - voucher_type = "Sales Invoice" else: invoice = frappe.get_doc("Purchase Invoice", invoice) account = pe.paid_to @@ -2927,9 +2926,8 @@ def make_advance_liability_entry( rev = "debit" against = invoice.credit_to party = invoice.supplier - voucher_type = "Purchase Invoice" gl_entries.append( - invoice.get_gl_dict( + pe.get_gl_dict( { "account": account, "party_type": party_type, @@ -2940,42 +2938,35 @@ def make_advance_liability_entry( dr_or_cr + "_in_account_currency": allocated_amount, rev: 0, rev + "_in_account_currency": 0, - "against_voucher": pe.name, - "against_voucher_type": "Payment Entry", "cost_center": invoice.cost_center, "project": invoice.project, - "voucher_type": voucher_type, - "voucher_no": invoice.name, + "against_voucher_type": "Payment Entry", + "against_voucher": pe.name, }, invoice.party_account_currency, - item=invoice, + item=pe, ) ) (dr_or_cr, rev) = ("credit", "debit") if party_type == "Customer" else ("debit", "credit") gl_entries.append( - invoice.get_gl_dict( + pe.get_gl_dict( { "account": against, "party_type": party_type, "party": party, "due_date": invoice.due_date, - "against": account, dr_or_cr: allocated_amount, dr_or_cr + "_in_account_currency": allocated_amount, rev: 0, rev + "_in_account_currency": 0, - "against_voucher": invoice.return_against - if cint(invoice.is_return) and invoice.return_against - else invoice.name, - "against_voucher_type": invoice.doctype, "cost_center": invoice.cost_center, "project": invoice.project, - "voucher_type": "Payment Entry" if references else voucher_type, - "voucher_no": pe.name if references else invoice.name, + "against_voucher_type": invoice.doctype, + "against_voucher": invoice.name, }, invoice.party_account_currency, - item=invoice, + item=pe, ) ) diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index 3523af1988f..611e2ab2210 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -72,9 +72,9 @@ "default_finance_book", "advance_payments_section", "book_advance_payments_as_liability", + "column_break_fwcf", "default_advance_received_account", "default_advance_paid_account", - "column_break_cui0", "auto_accounting_for_stock_settings", "enable_perpetual_inventory", "enable_provisional_accounting_for_non_stock_items", @@ -702,19 +702,16 @@ }, { "default": "0", + "description": "Enabling this option will allow you to record -

1. Advances Received in a Liability Account instead of the Receivable Account

2. Advances Paid in an Asset Account instead of the Payable Account", "fieldname": "book_advance_payments_as_liability", "fieldtype": "Check", - "label": "Book Advance Payments as Liability" + "label": "Book Advance Payments in Separate Party Account" }, { "fieldname": "advance_payments_section", "fieldtype": "Section Break", "label": "Advance Payments" }, - { - "fieldname": "column_break_cui0", - "fieldtype": "Column Break" - }, { "depends_on": "eval:doc.book_advance_payments_as_liability", "fieldname": "default_advance_received_account", @@ -730,6 +727,10 @@ "label": "Default Advance Paid Account", "mandatory_depends_on": "book_advance_payments_as_liability", "options": "Account" + }, + { + "fieldname": "column_break_fwcf", + "fieldtype": "Column Break" } ], "icon": "fa fa-building", @@ -737,7 +738,7 @@ "image_field": "company_logo", "is_tree": 1, "links": [], - "modified": "2023-06-12 12:51:12.007410", + "modified": "2023-06-16 13:32:48.790947", "modified_by": "Administrator", "module": "Setup", "name": "Company",