fix: render missing terms before printing (#58358)

This commit is contained in:
Pandiyan P
2026-08-24 14:53:08 +05:30
committed by GitHub
parent 7149df398a
commit 59d80b29c4
3 changed files with 20 additions and 24 deletions

View File

@@ -535,6 +535,8 @@ class AccountsController(TransactionBase):
frappe.throw(_("To Date cannot be before From Date"), title=_("Invalid Auto Repeat Date"))
def before_print(self, settings=None):
self.set_missing_terms()
if self.doctype in [
"Purchase Order",
"Sales Order",
@@ -558,6 +560,16 @@ class AccountsController(TransactionBase):
set_print_templates_for_item_table(self, settings)
set_print_templates_for_taxes(self, settings)
def set_missing_terms(self):
if not self.get("tc_name") or self.get("terms"):
return
from erpnext.setup.doctype.terms_and_conditions.terms_and_conditions import (
get_terms_and_conditions,
)
self.terms = get_terms_and_conditions(self.tc_name, self.as_dict())
def calculate_paid_amount(self):
if hasattr(self, "is_pos") or hasattr(self, "is_paid"):
is_paid = self.get("is_pos") or self.get("is_paid")

View File

@@ -84,18 +84,10 @@ class BuyingController(SubcontractingController):
),
)
if (
self.get("company")
and (
default_buying_terms := frappe.get_value(
"Company", self.get("company"), "default_buying_terms"
)
)
and not self.get("tc_name")
and not self.get("terms")
):
self.tc_name = default_buying_terms
self.terms = frappe.get_value("Terms and Conditions", self.get("tc_name"), "terms")
if self.get("company") and not self.get("terms"):
if not self.get("tc_name"):
self.tc_name = frappe.get_value("Company", self.company, "default_buying_terms")
self.set_missing_terms()
def validate_posting_date_with_po(self):
po_list = {x.purchase_order for x in self.items if x.purchase_order}

View File

@@ -44,18 +44,10 @@ class SellingController(StockController):
),
)
if (
self.get("company")
and (
default_selling_terms := frappe.get_value(
"Company", self.get("company"), "default_selling_terms"
)
)
and not self.get("tc_name")
and not self.get("terms")
):
self.tc_name = default_selling_terms
self.terms = frappe.get_value("Terms and Conditions", self.get("tc_name"), "terms")
if self.get("company") and not self.get("terms"):
if not self.get("tc_name"):
self.tc_name = frappe.get_value("Company", self.company, "default_selling_terms")
self.set_missing_terms()
def validate(self):
super().validate()