Skip to content

Commit

Permalink
fix(Delivery Note): translatability of validation errors
Browse files Browse the repository at this point in the history
(cherry picked from commit 34df6e3)
  • Loading branch information
barredterra authored and mergify[bot] committed Sep 9, 2024
1 parent 346c069 commit ea4f736
Showing 1 changed file with 28 additions and 38 deletions.
66 changes: 28 additions & 38 deletions erpnext/stock/doctype/delivery_note/delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,52 +362,42 @@ def validate_references(self):
self.validate_sales_invoice_references()

def validate_sales_order_references(self):
err_msg = ""
errors = []
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>"
missing_label = None
if item.against_sales_order and not item.so_detail:
missing_label = item.meta.get_label("so_detail")
elif item.so_detail and not item.against_sales_order:
missing_label = item.meta.get_label("against_sales_order")

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 Orders are Incomplete"))
if errors:
frappe.throw("<br>".join(errors), title=_("References to Sales Orders are Incomplete"))

def validate_sales_invoice_references(self):
err_msg = ""
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.against_sales_invoice and not item.si_detail:
missing_label = item.meta.get_label("si_detail")
elif item.si_detail and not item.against_sales_invoice:
missing_label = item.meta.get_label("against_sales_invoice")

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=_("References to Sales Invoices are Incomplete"))

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

0 comments on commit ea4f736

Please sign in to comment.