mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-30 18:34:48 +00:00
refactor: check_stock_uom_with_bin
This commit is contained in:
@@ -1183,27 +1183,25 @@ def check_stock_uom_with_bin(item, stock_uom):
|
|||||||
if stock_uom == frappe.db.get_value("Item", item, "stock_uom"):
|
if stock_uom == frappe.db.get_value("Item", item, "stock_uom"):
|
||||||
return
|
return
|
||||||
|
|
||||||
matched = True
|
|
||||||
ref_uom = frappe.db.get_value("Stock Ledger Entry",
|
ref_uom = frappe.db.get_value("Stock Ledger Entry",
|
||||||
{"item_code": item}, "stock_uom")
|
{"item_code": item}, "stock_uom")
|
||||||
|
|
||||||
if ref_uom:
|
if ref_uom:
|
||||||
if cstr(ref_uom) != cstr(stock_uom):
|
if cstr(ref_uom) != cstr(stock_uom):
|
||||||
matched = False
|
frappe.throw(_("Default Unit of Measure for Item {0} cannot be changed directly because you have already made some transaction(s) with another UOM. You will need to create a new Item to use a different Default UOM.").format(item))
|
||||||
else:
|
|
||||||
bin_list = frappe.db.sql("select * from tabBin where item_code=%s", item, as_dict=1)
|
|
||||||
for bin in bin_list:
|
|
||||||
if (bin.reserved_qty > 0 or bin.ordered_qty > 0 or bin.indented_qty > 0
|
|
||||||
or bin.planned_qty > 0) and cstr(bin.stock_uom) != cstr(stock_uom):
|
|
||||||
matched = False
|
|
||||||
break
|
|
||||||
|
|
||||||
if matched and bin_list:
|
bin_list = frappe.db.sql("""
|
||||||
frappe.db.sql("""update tabBin set stock_uom=%s where item_code=%s""", (stock_uom, item))
|
select * from tabBin where item_code = %s
|
||||||
|
and (reserved_qty > 0 or ordered_qty > 0 or indented_qty > 0 or planned_qty > 0)
|
||||||
|
and stock_uom != %s
|
||||||
|
""", (item, stock_uom), as_dict=1)
|
||||||
|
|
||||||
|
if bin_list:
|
||||||
|
frappe.throw(_("Default Unit of Measure for Item {0} cannot be changed directly because you have already made some transaction(s) with another UOM. You need to either cancel the linked documents or create a new Item.").format(item))
|
||||||
|
|
||||||
|
# No SLE or documents against item. Bin UOM can be changed safely.
|
||||||
|
frappe.db.sql("""update tabBin set stock_uom=%s where item_code=%s""", (stock_uom, item))
|
||||||
|
|
||||||
if not matched:
|
|
||||||
frappe.throw(
|
|
||||||
_("Default Unit of Measure for Item {0} cannot be changed directly because you have already made some transaction(s) with another UOM. You will need to create a new Item to use a different Default UOM.").format(item))
|
|
||||||
|
|
||||||
def get_item_defaults(item_code, company):
|
def get_item_defaults(item_code, company):
|
||||||
item = frappe.get_cached_doc('Item', item_code)
|
item = frappe.get_cached_doc('Item', item_code)
|
||||||
|
|||||||
Reference in New Issue
Block a user