fix: update outstanding amount and unpaid status on cancellation of payment entry
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 40dcc8c..d901faa 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -872,7 +872,7 @@
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 @@
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 @@
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 @@
{
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 a929ff1..a0954a9 100644
--- a/erpnext/accounts/general_ledger.py
+++ b/erpnext/accounts/general_ledger.py
@@ -223,6 +223,7 @@
"party_type",
"project",
"finance_book",
+ "voucher_no",
]
if dimensions:
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index abf9b5e..e69dcd4 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -437,7 +437,7 @@
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 578b26a..f564840 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -1021,7 +1021,7 @@
)
)
- 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 @@
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 @@
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 @@
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 @@
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 3523af1..611e2ab 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,9 +702,10 @@
},
{
"default": "0",
+ "description": "Enabling this option will allow you to record - <br><br> 1. Advances Received in a <b>Liability Account</b> instead of the <b>Receivable Account</b><br><br>2. Advances Paid in an <b>Asset Account</b> instead of the <b> Payable Account</b>",
"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",
@@ -712,10 +713,6 @@
"label": "Advance Payments"
},
{
- "fieldname": "column_break_cui0",
- "fieldtype": "Column Break"
- },
- {
"depends_on": "eval:doc.book_advance_payments_as_liability",
"fieldname": "default_advance_received_account",
"fieldtype": "Link",
@@ -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",