mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-23 04:04:52 +00:00
perf: optimize DB calls with frappe.get_all (#45289)
* perf: reduce multiple db queries
* fix: use frappe._dict instread of extra iteration
---------
Co-authored-by: Sanket322 <shahsanket322003.com>
(cherry picked from commit 2a400dd3f8)
Co-authored-by: Sanket Shah <113279972+Sanket322@users.noreply.github.com>
This commit is contained in:
@@ -714,6 +714,16 @@ class SellingController(StockController):
|
|||||||
if self.doctype == "POS Invoice":
|
if self.doctype == "POS Invoice":
|
||||||
return
|
return
|
||||||
|
|
||||||
|
items = [item.item_code for item in self.get("items")]
|
||||||
|
item_stock_map = frappe._dict(
|
||||||
|
frappe.get_all(
|
||||||
|
"Item",
|
||||||
|
filters={"item_code": ["in", items]},
|
||||||
|
fields=["item_code", "is_stock_item"],
|
||||||
|
as_list=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
for d in self.get("items"):
|
for d in self.get("items"):
|
||||||
if self.doctype == "Sales Invoice":
|
if self.doctype == "Sales Invoice":
|
||||||
stock_items = [
|
stock_items = [
|
||||||
@@ -747,7 +757,7 @@ class SellingController(StockController):
|
|||||||
frappe.bold(_("Allow Item to Be Added Multiple Times in a Transaction")),
|
frappe.bold(_("Allow Item to Be Added Multiple Times in a Transaction")),
|
||||||
get_link_to_form("Selling Settings", "Selling Settings"),
|
get_link_to_form("Selling Settings", "Selling Settings"),
|
||||||
)
|
)
|
||||||
if frappe.db.get_value("Item", d.item_code, "is_stock_item") == 1:
|
if item_stock_map.get(d.item_code):
|
||||||
if stock_items in check_list:
|
if stock_items in check_list:
|
||||||
frappe.throw(duplicate_items_msg)
|
frappe.throw(duplicate_items_msg)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user