mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 18:59:08 +00:00
refactor: remove duplicate reconciliation date logic
This commit is contained in:
@@ -47,6 +47,7 @@ from erpnext.accounts.utils import (
|
|||||||
cancel_exchange_gain_loss_journal,
|
cancel_exchange_gain_loss_journal,
|
||||||
get_account_currency,
|
get_account_currency,
|
||||||
get_outstanding_invoices,
|
get_outstanding_invoices,
|
||||||
|
get_reconciliation_effect_date,
|
||||||
)
|
)
|
||||||
from erpnext.controllers.accounts_controller import (
|
from erpnext.controllers.accounts_controller import (
|
||||||
AccountsController,
|
AccountsController,
|
||||||
@@ -1570,23 +1571,7 @@ class PaymentEntry(AccountsController):
|
|||||||
else:
|
else:
|
||||||
# For backwards compatibility
|
# For backwards compatibility
|
||||||
# Supporting reposting on payment entries reconciled before select field introduction
|
# Supporting reposting on payment entries reconciled before select field introduction
|
||||||
reconciliation_takes_effect_on = frappe.get_cached_value(
|
posting_date = get_reconciliation_effect_date(invoice, self.company, self.posting_date)
|
||||||
"Company", self.company, "reconciliation_takes_effect_on"
|
|
||||||
)
|
|
||||||
if reconciliation_takes_effect_on == "Advance Payment Date":
|
|
||||||
posting_date = self.posting_date
|
|
||||||
elif 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 reconciliation_takes_effect_on == "Reconciliation Date":
|
|
||||||
posting_date = nowdate()
|
|
||||||
frappe.db.set_value("Payment Entry Reference", invoice.name, "reconcile_effect_on", 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)
|
dr_or_cr, account = self.get_dr_and_account_for_advances(invoice)
|
||||||
|
|||||||
@@ -731,23 +731,8 @@ def update_reference_in_payment_entry(
|
|||||||
update_advance_paid = []
|
update_advance_paid = []
|
||||||
|
|
||||||
# Update Reconciliation effect date in reference
|
# Update Reconciliation effect date in reference
|
||||||
reconciliation_takes_effect_on = frappe.get_cached_value(
|
|
||||||
"Company", payment_entry.company, "reconciliation_takes_effect_on"
|
|
||||||
)
|
|
||||||
if payment_entry.book_advance_payments_in_separate_party_account:
|
if payment_entry.book_advance_payments_in_separate_party_account:
|
||||||
if reconciliation_takes_effect_on == "Advance Payment Date":
|
reconcile_on = get_reconciliation_effect_date(d, payment_entry.company, payment_entry.posting_date)
|
||||||
reconcile_on = payment_entry.posting_date
|
|
||||||
elif reconciliation_takes_effect_on == "Oldest Of Invoice Or Advance":
|
|
||||||
date_field = "posting_date"
|
|
||||||
if d.against_voucher_type in ["Sales Order", "Purchase Order"]:
|
|
||||||
date_field = "transaction_date"
|
|
||||||
reconcile_on = frappe.db.get_value(d.against_voucher_type, d.against_voucher, date_field)
|
|
||||||
|
|
||||||
if getdate(reconcile_on) < getdate(payment_entry.posting_date):
|
|
||||||
reconcile_on = payment_entry.posting_date
|
|
||||||
elif reconciliation_takes_effect_on == "Reconciliation Date":
|
|
||||||
reconcile_on = nowdate()
|
|
||||||
|
|
||||||
reference_details.update({"reconcile_effect_on": reconcile_on})
|
reference_details.update({"reconcile_effect_on": reconcile_on})
|
||||||
|
|
||||||
if d.voucher_detail_no:
|
if d.voucher_detail_no:
|
||||||
@@ -805,6 +790,28 @@ def update_reference_in_payment_entry(
|
|||||||
return row, update_advance_paid
|
return row, update_advance_paid
|
||||||
|
|
||||||
|
|
||||||
|
def get_reconciliation_effect_date(reference, company, posting_date):
|
||||||
|
reconciliation_takes_effect_on = frappe.get_cached_value(
|
||||||
|
"Company", company, "reconciliation_takes_effect_on"
|
||||||
|
)
|
||||||
|
|
||||||
|
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"]:
|
||||||
|
date_field = "transaction_date"
|
||||||
|
reconcile_on = frappe.db.get_value(
|
||||||
|
reference.against_voucher_type, reference.against_voucher, date_field
|
||||||
|
)
|
||||||
|
if getdate(reconcile_on) < getdate(posting_date):
|
||||||
|
reconcile_on = posting_date
|
||||||
|
elif reconciliation_takes_effect_on == "Reconciliation Date":
|
||||||
|
reconcile_on = nowdate()
|
||||||
|
|
||||||
|
return reconcile_on
|
||||||
|
|
||||||
|
|
||||||
def cancel_exchange_gain_loss_journal(
|
def cancel_exchange_gain_loss_journal(
|
||||||
parent_doc: dict | object, referenced_dt: str | None = None, referenced_dn: str | None = None
|
parent_doc: dict | object, referenced_dt: str | None = None, referenced_dn: str | None = None
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user