diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 8a0bd527e1c..0cf91dceb16 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1560,13 +1560,14 @@ class PaymentEntry(AccountsController): "voucher_no": self.name, "voucher_detail_no": invoice.name, } - 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 - posting_date = get_reconciliation_effect_date(invoice, self.company, self.posting_date) + posting_date = get_reconciliation_effect_date( + invoice.reference_doctype, invoice.reference_name, self.company, self.posting_date + ) 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) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index dcb05d7040a..5aca7dd04cc 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -732,7 +732,9 @@ def update_reference_in_payment_entry( # Update Reconciliation effect date in reference if payment_entry.book_advance_payments_in_separate_party_account: - reconcile_on = get_reconciliation_effect_date(d, payment_entry.company, payment_entry.posting_date) + reconcile_on = get_reconciliation_effect_date( + d.against_voucher_type, d.against_voucher, payment_entry.company, payment_entry.posting_date + ) reference_details.update({"reconcile_effect_on": reconcile_on}) if d.voucher_detail_no: @@ -787,20 +789,21 @@ def update_reference_in_payment_entry( return row, update_advance_paid -def get_reconciliation_effect_date(reference, company, posting_date): +def get_reconciliation_effect_date(against_voucher_type, against_voucher, company, posting_date): reconciliation_takes_effect_on = frappe.get_cached_value( "Company", company, "reconciliation_takes_effect_on" ) + # default + reconcile_on = posting_date + if reconciliation_takes_effect_on == "Advance Payment Date": reconcile_on = posting_date elif reconciliation_takes_effect_on == "Oldest Of Invoice Or Advance": date_field = "posting_date" - if reference.against_voucher_type in ["Sales Order", "Purchase Order"]: + if against_voucher_type in ["Sales Order", "Purchase Order"]: date_field = "transaction_date" - reconcile_on = frappe.db.get_value( - reference.against_voucher_type, reference.against_voucher, date_field - ) + reconcile_on = frappe.db.get_value(against_voucher_type, against_voucher, date_field) if getdate(reconcile_on) < getdate(posting_date): reconcile_on = posting_date elif reconciliation_takes_effect_on == "Reconciliation Date":