refactor: use frappe.throw instread of recreating
_msgprint was basically duplicating behvaiour of frappe.throw
This commit is contained in:
parent
1097dc89c5
commit
330353a5ce
@ -1068,42 +1068,31 @@ def get_timeline_data(doctype, name):
|
||||
return out
|
||||
|
||||
|
||||
def validate_end_of_life(item_code, end_of_life=None, disabled=None, verbose=1):
|
||||
def validate_end_of_life(item_code, end_of_life=None, disabled=None):
|
||||
if (not end_of_life) or (disabled is None):
|
||||
end_of_life, disabled = frappe.db.get_value("Item", item_code, ["end_of_life", "disabled"])
|
||||
|
||||
if end_of_life and end_of_life != "0000-00-00" and getdate(end_of_life) <= now_datetime().date():
|
||||
msg = _("Item {0} has reached its end of life on {1}").format(item_code, formatdate(end_of_life))
|
||||
_msgprint(msg, verbose)
|
||||
frappe.throw(_("Item {0} has reached its end of life on {1}").format(item_code, formatdate(end_of_life)))
|
||||
|
||||
if disabled:
|
||||
_msgprint(_("Item {0} is disabled").format(item_code), verbose)
|
||||
frappe.throw(_("Item {0} is disabled").format(item_code))
|
||||
|
||||
|
||||
def validate_is_stock_item(item_code, is_stock_item=None, verbose=1):
|
||||
def validate_is_stock_item(item_code, is_stock_item=None):
|
||||
if not is_stock_item:
|
||||
is_stock_item = frappe.db.get_value("Item", item_code, "is_stock_item")
|
||||
|
||||
if is_stock_item != 1:
|
||||
msg = _("Item {0} is not a stock Item").format(item_code)
|
||||
|
||||
_msgprint(msg, verbose)
|
||||
frappe.throw(_("Item {0} is not a stock Item").format(item_code))
|
||||
|
||||
|
||||
def validate_cancelled_item(item_code, docstatus=None, verbose=1):
|
||||
def validate_cancelled_item(item_code, docstatus=None):
|
||||
if docstatus is None:
|
||||
docstatus = frappe.db.get_value("Item", item_code, "docstatus")
|
||||
|
||||
if docstatus == 2:
|
||||
msg = _("Item {0} is cancelled").format(item_code)
|
||||
_msgprint(msg, verbose)
|
||||
|
||||
def _msgprint(msg, verbose):
|
||||
if verbose:
|
||||
msgprint(msg, raise_exception=True)
|
||||
else:
|
||||
raise frappe.ValidationError(msg)
|
||||
|
||||
frappe.throw(_("Item {0} is cancelled").format(item_code))
|
||||
|
||||
def get_last_purchase_details(item_code, doc_name=None, conversion_rate=1.0):
|
||||
"""returns last purchase details in stock uom"""
|
||||
|
@ -167,8 +167,8 @@ class StockReconciliation(StockController):
|
||||
item = frappe.get_doc("Item", item_code)
|
||||
|
||||
# end of life and stock item
|
||||
validate_end_of_life(item_code, item.end_of_life, item.disabled, verbose=0)
|
||||
validate_is_stock_item(item_code, item.is_stock_item, verbose=0)
|
||||
validate_end_of_life(item_code, item.end_of_life, item.disabled)
|
||||
validate_is_stock_item(item_code, item.is_stock_item)
|
||||
|
||||
# item should not be serialized
|
||||
if item.has_serial_no and not row.serial_no and not item.serial_no_series:
|
||||
@ -179,7 +179,7 @@ class StockReconciliation(StockController):
|
||||
raise frappe.ValidationError(_("Batch no is required for batched item {0}").format(item_code))
|
||||
|
||||
# docstatus should be < 2
|
||||
validate_cancelled_item(item_code, item.docstatus, verbose=0)
|
||||
validate_cancelled_item(item_code, item.docstatus)
|
||||
|
||||
except Exception as e:
|
||||
self.validation_messages.append(_("Row # ") + ("%d: " % (row.idx)) + cstr(e))
|
||||
|
Loading…
Reference in New Issue
Block a user