From 7f147446df1382fe73946906c9f20c9d82b3bc04 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:30:14 +0530 Subject: [PATCH] fix: calculate due date based on payment term (backport #46416) (#46479) fix: calculate due date based on payment term (#46416) (cherry picked from commit 9e808c832f4cce536fe5d4f16d3f550352ba6f49) Co-authored-by: Sudharsanan Ashok <135326972+Sudharsanan11@users.noreply.github.com> --- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 8 +++++++- erpnext/accounts/party.py | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 92902c78e8e..673a65dae55 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -678,7 +678,13 @@ class SalesInvoice(SellingController): "Account", self.debit_to, "account_currency", cache=True ) if not self.due_date and self.customer: - self.due_date = get_due_date(self.posting_date, "Customer", self.customer, self.company) + self.due_date = get_due_date( + self.posting_date, + "Customer", + self.customer, + self.company, + template_name=self.payment_terms_template, + ) super().set_missing_values(for_validate) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index f2e86ef2b2e..959e3429095 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -572,12 +572,13 @@ def validate_party_accounts(doc): @frappe.whitelist() -def get_due_date(posting_date, party_type, party, company=None, bill_date=None): +def get_due_date(posting_date, party_type, party, company=None, bill_date=None, template_name=None): """Get due date from `Payment Terms Template`""" due_date = None if (bill_date or posting_date) and party: due_date = bill_date or posting_date - template_name = get_payment_terms_template(party, party_type, company) + if not template_name: + template_name = get_payment_terms_template(party, party_type, company) if template_name: due_date = get_due_date_from_template(template_name, posting_date, bill_date).strftime("%Y-%m-%d")