perf: don't query unless required (bp #26175)
re-order conditionals so queries are not evaluated unless required. # Conflicts: # erpnext/stock/doctype/batch/batch.py
This commit is contained in:
parent
b4b76b75cd
commit
21e44b19f0
@ -99,9 +99,10 @@ def validate_returned_items(doc):
|
|||||||
frappe.throw(_("Row # {0}: Serial No {1} does not match with {2} {3}")
|
frappe.throw(_("Row # {0}: Serial No {1} does not match with {2} {3}")
|
||||||
.format(d.idx, s, doc.doctype, doc.return_against))
|
.format(d.idx, s, doc.doctype, doc.return_against))
|
||||||
|
|
||||||
if warehouse_mandatory and frappe.db.get_value("Item", d.item_code, "is_stock_item") \
|
if (warehouse_mandatory and not d.get("warehouse") and
|
||||||
and not d.get("warehouse"):
|
frappe.db.get_value("Item", d.item_code, "is_stock_item")
|
||||||
frappe.throw(_("Warehouse is mandatory"))
|
):
|
||||||
|
frappe.throw(_("Warehouse is mandatory"))
|
||||||
|
|
||||||
items_returned = True
|
items_returned = True
|
||||||
|
|
||||||
@ -462,4 +463,4 @@ def get_returned_serial_nos(child_doc, parent_doc):
|
|||||||
for row in frappe.get_all(parent_doc.doctype, fields = fields, filters=filters):
|
for row in frappe.get_all(parent_doc.doctype, fields = fields, filters=filters):
|
||||||
serial_nos.extend(get_serial_nos(row.serial_no))
|
serial_nos.extend(get_serial_nos(row.serial_no))
|
||||||
|
|
||||||
return serial_nos
|
return serial_nos
|
||||||
|
@ -230,9 +230,8 @@ def set_batch_nos(doc, warehouse_field, throw=False, child_table="items"):
|
|||||||
"""Automatically select `batch_no` for outgoing items in item table"""
|
"""Automatically select `batch_no` for outgoing items in item table"""
|
||||||
for d in doc.get(child_table):
|
for d in doc.get(child_table):
|
||||||
qty = d.get('stock_qty') or d.get('transfer_qty') or d.get('qty') or 0
|
qty = d.get('stock_qty') or d.get('transfer_qty') or d.get('qty') or 0
|
||||||
has_batch_no = frappe.db.get_value('Item', d.item_code, 'has_batch_no')
|
|
||||||
warehouse = d.get(warehouse_field, None)
|
warehouse = d.get(warehouse_field, None)
|
||||||
if has_batch_no and warehouse and qty > 0:
|
if warehouse and qty > 0 and frappe.db.get_value('Item', d.item_code, 'has_batch_no'):
|
||||||
if not d.batch_no:
|
if not d.batch_no:
|
||||||
d.batch_no = get_batch_no(d.item_code, warehouse, qty, throw, d.serial_no)
|
d.batch_no = get_batch_no(d.item_code, warehouse, qty, throw, d.serial_no)
|
||||||
else:
|
else:
|
||||||
@ -313,4 +312,4 @@ def validate_serial_no_with_batch(serial_nos, item_code):
|
|||||||
def make_batch(args):
|
def make_batch(args):
|
||||||
if frappe.db.get_value("Item", args.item, "has_batch_no"):
|
if frappe.db.get_value("Item", args.item, "has_batch_no"):
|
||||||
args.doctype = "Batch"
|
args.doctype = "Batch"
|
||||||
frappe.get_doc(args).insert().name
|
frappe.get_doc(args).insert().name
|
||||||
|
@ -182,9 +182,8 @@ class DeliveryNote(SellingController):
|
|||||||
super(DeliveryNote, self).validate_warehouse()
|
super(DeliveryNote, self).validate_warehouse()
|
||||||
|
|
||||||
for d in self.get_item_list():
|
for d in self.get_item_list():
|
||||||
if frappe.db.get_value("Item", d['item_code'], "is_stock_item") == 1:
|
if not d['warehouse'] and frappe.db.get_value("Item", d['item_code'], "is_stock_item") == 1:
|
||||||
if not d['warehouse']:
|
frappe.throw(_("Warehouse required for stock Item {0}").format(d["item_code"]))
|
||||||
frappe.throw(_("Warehouse required for stock Item {0}").format(d["item_code"]))
|
|
||||||
|
|
||||||
|
|
||||||
def update_current_stock(self):
|
def update_current_stock(self):
|
||||||
|
@ -189,7 +189,7 @@ class MaterialRequest(BuyingController):
|
|||||||
item_wh_list = []
|
item_wh_list = []
|
||||||
for d in self.get("items"):
|
for d in self.get("items"):
|
||||||
if (not mr_item_rows or d.name in mr_item_rows) and [d.item_code, d.warehouse] not in item_wh_list \
|
if (not mr_item_rows or d.name in mr_item_rows) and [d.item_code, d.warehouse] not in item_wh_list \
|
||||||
and frappe.db.get_value("Item", d.item_code, "is_stock_item") == 1 and d.warehouse:
|
and d.warehouse and frappe.db.get_value("Item", d.item_code, "is_stock_item") == 1 :
|
||||||
item_wh_list.append([d.item_code, d.warehouse])
|
item_wh_list.append([d.item_code, d.warehouse])
|
||||||
|
|
||||||
for item_code, warehouse in item_wh_list:
|
for item_code, warehouse in item_wh_list:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user