mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-17 16:38:41 +00:00
fix(accounts): clear clearance date when amending reconciled voucher
The framework ignores `no_copy` while amending, so a reconciled voucher
carried a stale clearance date into its amendment even though the linked
bank transaction gets unreconciled on cancellation. Reset it via a shared
`before_insert` hook on AccountsController.
Fixes #54909
(cherry picked from commit 1a8d73cbbe)
This commit is contained in:
@@ -104,6 +104,36 @@ class TestBankTransaction(ERPNextTestSuite):
|
|||||||
self.assertEqual(bank_transaction.unallocated_amount, 1700)
|
self.assertEqual(bank_transaction.unallocated_amount, 1700)
|
||||||
self.assertEqual(bank_transaction.payment_entries, [])
|
self.assertEqual(bank_transaction.payment_entries, [])
|
||||||
|
|
||||||
|
# Amending a reconciled payment entry must not carry over its clearance date
|
||||||
|
def test_clearance_date_cleared_on_amend(self):
|
||||||
|
bank_transaction = frappe.get_doc(
|
||||||
|
"Bank Transaction",
|
||||||
|
dict(description="1512567 BG/000003025 OPSKATTUZWXXX AT776000000098709849 Herr G"),
|
||||||
|
)
|
||||||
|
payment = frappe.get_doc("Payment Entry", dict(party="Mr G", paid_amount=1700))
|
||||||
|
vouchers = json.dumps(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"payment_doctype": "Payment Entry",
|
||||||
|
"payment_name": payment.name,
|
||||||
|
"amount": bank_transaction.unallocated_amount,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
reconcile_vouchers(bank_transaction.name, vouchers)
|
||||||
|
|
||||||
|
self.assertTrue(frappe.db.get_value("Payment Entry", payment.name, "clearance_date"))
|
||||||
|
|
||||||
|
payment.reload()
|
||||||
|
payment.cancel()
|
||||||
|
|
||||||
|
amended = frappe.copy_doc(payment)
|
||||||
|
amended.amended_from = payment.name
|
||||||
|
amended.docstatus = 0
|
||||||
|
amended.insert()
|
||||||
|
|
||||||
|
self.assertFalse(amended.clearance_date)
|
||||||
|
|
||||||
# Check if ERPNext can correctly filter a linked payments based on the debit/credit amount
|
# Check if ERPNext can correctly filter a linked payments based on the debit/credit amount
|
||||||
def test_debit_credit_output(self):
|
def test_debit_credit_output(self):
|
||||||
bank_transaction = frappe.get_doc(
|
bank_transaction = frappe.get_doc(
|
||||||
|
|||||||
@@ -140,6 +140,26 @@ class AccountsController(TransactionBase):
|
|||||||
if self.doctype in relevant_docs:
|
if self.doctype in relevant_docs:
|
||||||
self.set_payment_schedule()
|
self.set_payment_schedule()
|
||||||
|
|
||||||
|
def before_insert(self):
|
||||||
|
self.clear_clearance_date_on_amend()
|
||||||
|
|
||||||
|
def clear_clearance_date_on_amend(self):
|
||||||
|
"""Drop the bank reconciliation clearance date copied over while amending.
|
||||||
|
|
||||||
|
The framework copies `no_copy` fields when amending, so a reconciled
|
||||||
|
voucher would carry a stale clearance date into its amendment even though
|
||||||
|
the linked bank transaction gets unreconciled on cancellation.
|
||||||
|
"""
|
||||||
|
if not self.get("amended_from"):
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.meta.has_field("clearance_date"):
|
||||||
|
self.clearance_date = None
|
||||||
|
|
||||||
|
for payment in self.get("payments") or []:
|
||||||
|
if payment.meta.has_field("clearance_date"):
|
||||||
|
payment.clearance_date = None
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
from erpnext.controllers.taxes_and_totals import process_item_wise_tax_details
|
from erpnext.controllers.taxes_and_totals import process_item_wise_tax_details
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user