Merge pull request #47415 from frappe/mergify/bp/version-14-hotfix/pr-47408

fix: show party type in due date exceeding message (backport #47408)
This commit is contained in:
ruthra kumar
2025-05-06 14:32:58 +05:30
committed by GitHub
2 changed files with 23 additions and 21 deletions

View File

@@ -597,35 +597,34 @@ def get_due_date_from_template(template_name, posting_date, bill_date):
def validate_due_date( def validate_due_date(
posting_date, due_date, party_type, party, company=None, bill_date=None, template_name=None posting_date, due_date, party_type, party, company=None, bill_date=None, template_name=None, doctype=None
): ):
if getdate(due_date) < getdate(posting_date): if getdate(due_date) < getdate(posting_date):
frappe.throw(_("Due Date cannot be before Posting / Supplier Invoice Date")) frappe.throw(_("Due Date cannot be before Posting / Supplier Invoice Date"))
else: else:
validate_due_date_with_template(posting_date, due_date, bill_date, template_name, doctype)
def validate_due_date_with_template(posting_date, due_date, bill_date, template_name, doctype=None):
if not template_name: if not template_name:
return return
default_due_date = get_due_date_from_template(template_name, posting_date, bill_date).strftime( default_due_date = format(get_due_date_from_template(template_name, posting_date, bill_date))
"%Y-%m-%d"
)
if not default_due_date: if not default_due_date:
return return
if default_due_date != posting_date and getdate(due_date) > getdate(default_due_date): if default_due_date != posting_date and getdate(due_date) > getdate(default_due_date):
is_credit_controller = ( if frappe.db.get_single_value("Accounts Settings", "credit_controller") in frappe.get_roles():
frappe.db.get_single_value("Accounts Settings", "credit_controller") in frappe.get_roles() party_type = "supplier" if doctype == "Purchase Invoice" else "customer"
)
if is_credit_controller:
msgprint( msgprint(
_("Note: Due / Reference Date exceeds allowed customer credit days by {0} day(s)").format( _("Note: Due Date exceeds allowed {0} credit days by {1} day(s)").format(
date_diff(due_date, default_due_date) party_type, date_diff(due_date, default_due_date)
) )
) )
else: else:
frappe.throw( frappe.throw(_("Due Date cannot be after {0}").format(formatdate(default_due_date)))
_("Due / Reference Date cannot be after {0}").format(formatdate(default_due_date))
)
@frappe.whitelist() @frappe.whitelist()

View File

@@ -684,7 +684,9 @@ class AccountsController(TransactionBase):
"Customer", "Customer",
self.customer, self.customer,
self.company, self.company,
None,
self.payment_terms_template, self.payment_terms_template,
self.doctype,
) )
elif self.doctype == "Purchase Invoice": elif self.doctype == "Purchase Invoice":
validate_due_date( validate_due_date(
@@ -695,6 +697,7 @@ class AccountsController(TransactionBase):
self.company, self.company,
self.bill_date, self.bill_date,
self.payment_terms_template, self.payment_terms_template,
self.doctype,
) )
def set_price_list_currency(self, buying_or_selling): def set_price_list_currency(self, buying_or_selling):