Skip to content

Commit

Permalink
Merge pull request #44442 from frappe/mergify/bp/version-15-hotfix/pr…
Browse files Browse the repository at this point in the history
…-44440

perf: cache product bundle items at document level (backport #44440)
  • Loading branch information
sagarvora authored Nov 29, 2024
2 parents c81b5e3 + 1f97979 commit a1643ad
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions erpnext/controllers/selling_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,32 @@ def get_item_list(self):
return il

def has_product_bundle(self, item_code):
product_bundle = frappe.qb.DocType("Product Bundle")
return (
frappe.qb.from_(product_bundle)
.select(product_bundle.name)
.where((product_bundle.new_item_code == item_code) & (product_bundle.disabled == 0))
).run()
product_bundle_items = getattr(self, "_product_bundle_items", None)
if product_bundle_items is None:
self._product_bundle_items = product_bundle_items = {}

if item_code not in product_bundle_items:
self._fetch_product_bundle_items(item_code)

return product_bundle_items[item_code]

def _fetch_product_bundle_items(self, item_code):
product_bundle_items = self._product_bundle_items
items_to_fetch = {row.item_code for row in self.items if row.item_code not in product_bundle_items}
# fetch for requisite item_code even if it is not in items
items_to_fetch.add(item_code)

items_with_product_bundle = {
row.new_item_code
for row in frappe.get_all(
"Product Bundle",
filters={"new_item_code": ("in", items_to_fetch), "disabled": 0},
fields="new_item_code",
)
}

for item_code in items_to_fetch:
product_bundle_items[item_code] = item_code in items_with_product_bundle

def get_already_delivered_qty(self, current_docname, so, so_detail):
delivered_via_dn = frappe.db.sql(
Expand Down

0 comments on commit a1643ad

Please sign in to comment.