Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: dont run queries unnecessarily, improved filters #41993

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions erpnext/controllers/subcontracting_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,23 @@ def __update_consumed_materials(self, doctype, return_consumed_items=False):
receipt_items = {item.name: item.get(self.subcontract_data.order_field) for item in receipt_items}
consumed_materials = self.__get_consumed_items(doctype, receipt_items.keys())

voucher_nos = [d.voucher_no for d in consumed_materials if d.voucher_no]
voucher_bundle_data = get_voucher_wise_serial_batch_from_bundle(
voucher_no=voucher_nos,
is_outward=1,
get_subcontracted_item=("Subcontracting Receipt Supplied Item", "main_item_code"),
)

if return_consumed_items:
return (consumed_materials, receipt_items)

if not consumed_materials:
return

voucher_nos = [d.voucher_no for d in consumed_materials if d.voucher_no]
voucher_bundle_data = (
get_voucher_wise_serial_batch_from_bundle(
voucher_no=voucher_nos,
is_outward=1,
get_subcontracted_item=("Subcontracting Receipt Supplied Item", "main_item_code"),
)
if voucher_nos
else {}
)

for row in consumed_materials:
key = (row.rm_item_code, row.main_item_code, receipt_items.get(row.reference_name))
if not self.available_materials.get(key):
Expand Down Expand Up @@ -350,10 +357,14 @@ def get_available_materials(self):
transferred_items = self.__get_transferred_items()

voucher_nos = [row.voucher_no for row in transferred_items]
voucher_bundle_data = get_voucher_wise_serial_batch_from_bundle(
voucher_no=voucher_nos,
is_outward=0,
get_subcontracted_item=("Stock Entry Detail", "subcontracted_item"),
voucher_bundle_data = (
get_voucher_wise_serial_batch_from_bundle(
voucher_no=voucher_nos,
is_outward=0,
get_subcontracted_item=("Stock Entry Detail", "subcontracted_item"),
)
if voucher_nos
else {}
)

for row in transferred_items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2104,10 +2104,13 @@ def get_ledgers_from_serial_batch_bundle(**kwargs) -> list[frappe._dict]:
)

for key, val in kwargs.items():
if not val:
if val is None:
continue

if key in ["get_subcontracted_item"]:
if not val and isinstance(val, list):
return []

if key == "get_subcontracted_item":
continue

if key in ["name", "item_code", "warehouse", "voucher_no", "company", "voucher_detail_no"]:
Expand Down
Loading