From 9fa1865cb7864184176e415fb5502d0bf9ed2eaa Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 13 Jan 2025 17:17:18 +0530 Subject: [PATCH] refactor: backwards compatibility --- .../doctype/payment_entry/payment_entry.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 50c34cf7775..87576ec599d 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1507,7 +1507,27 @@ class PaymentEntry(AccountsController): "voucher_detail_no": invoice.name, } - posting_date = invoice.reconcile_effect_on + if invoice.reconcile_effect_on: + posting_date = invoice.reconcile_effect_on + else: + # For backwards compatibility + # Supporting reposting on payment entries reconciled before select field introduction + if self.advance_reconciliation_takes_effect_on == "Advance Payment Date": + posting_date = self.posting_date + elif self.advance_reconciliation_takes_effect_on == "Oldest Of Invoice Or Advance": + date_field = "posting_date" + if invoice.reference_doctype in ["Sales Order", "Purchase Order"]: + date_field = "transaction_date" + posting_date = frappe.db.get_value( + invoice.reference_doctype, invoice.reference_name, date_field + ) + + if getdate(posting_date) < getdate(self.posting_date): + posting_date = self.posting_date + elif self.advance_reconciliation_takes_effect_on == "Reconciliation Date": + posting_date = nowdate() + frappe.db.set_value("Payment Entry Reference", invoice.name, "reconcile_effect_on", posting_date) + dr_or_cr, account = self.get_dr_and_account_for_advances(invoice) args_dict["account"] = account args_dict[dr_or_cr] = self.calculate_base_allocated_amount_for_reference(invoice)