Skip to content

Commit

Permalink
Merge pull request #43129 from frappe/mergify/bp/version-15-hotfix/pr…
Browse files Browse the repository at this point in the history
…-42801

fix(Delivery Note): translatability of validation errors (backport #42801)
  • Loading branch information
ruthra-kumar committed Sep 9, 2024
2 parents 346c069 + 0c0f103 commit cf81202
Showing 1 changed file with 22 additions and 41 deletions.
63 changes: 22 additions & 41 deletions erpnext/stock/doctype/delivery_note/delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,52 +362,33 @@ def validate_references(self):
self.validate_sales_invoice_references()

def validate_sales_order_references(self):
err_msg = ""
for item in self.items:
if (item.against_sales_order and not item.so_detail) or (
not item.against_sales_order and item.so_detail
):
if not item.against_sales_order:
err_msg += (
_("'Sales Order' reference ({1}) is missing in row {0}").format(
frappe.bold(item.idx), frappe.bold("against_sales_order")
)
+ "<br>"
)
else:
err_msg += (
_("'Sales Order Item' reference ({1}) is missing in row {0}").format(
frappe.bold(item.idx), frappe.bold("so_detail")
)
+ "<br>"
)

if err_msg:
frappe.throw(err_msg, title=_("References to Sales Orders are Incomplete"))
self._validate_dependent_item_fields(
"against_sales_order", "so_detail", _("References to Sales Orders are Incomplete")
)

def validate_sales_invoice_references(self):
err_msg = ""
self._validate_dependent_item_fields(
"against_sales_invoice", "si_detail", _("References to Sales Invoices are Incomplete")
)

def _validate_dependent_item_fields(self, field_a: str, field_b: str, error_title: str):
errors = []
for item in self.items:
if (item.against_sales_invoice and not item.si_detail) or (
not item.against_sales_invoice and item.si_detail
):
if not item.against_sales_invoice:
err_msg += (
_("'Sales Invoice' reference ({1}) is missing in row {0}").format(
frappe.bold(item.idx), frappe.bold("against_sales_invoice")
)
+ "<br>"
)
else:
err_msg += (
_("'Sales Invoice Item' reference ({1}) is missing in row {0}").format(
frappe.bold(item.idx), frappe.bold("si_detail")
)
+ "<br>"
missing_label = None
if item.get(field_a) and not item.get(field_b):
missing_label = item.meta.get_label(field_b)
elif item.get(field_b) and not item.get(field_a):
missing_label = item.meta.get_label(field_a)

if missing_label and missing_label != "No Label":
errors.append(
_("The field {0} in row {1} is not set").format(
frappe.bold(_(missing_label)), frappe.bold(item.idx)
)
)

if err_msg:
frappe.throw(err_msg, title=_("References to Sales Invoices are Incomplete"))
if errors:
frappe.throw("<br>".join(errors), title=error_title)

def validate_proj_cust(self):
"""check for does customer belong to same project as entered.."""
Expand Down

0 comments on commit cf81202

Please sign in to comment.