From 40963448fe875131c208a6874d13f98556ceb20c Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Sat, 22 Jun 2024 19:13:59 +0530 Subject: [PATCH] refactor: remove minor code duplication --- .../controllers/subcontracting_controller.py | 24 +++++++------------ .../serial_and_batch_bundle.py | 3 +++ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/erpnext/controllers/subcontracting_controller.py b/erpnext/controllers/subcontracting_controller.py index d31ee258b27b6..aee69b7a6d011 100644 --- a/erpnext/controllers/subcontracting_controller.py +++ b/erpnext/controllers/subcontracting_controller.py @@ -301,14 +301,10 @@ def __update_consumed_materials(self, doctype, return_consumed_items=False): 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 {} + 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"), ) for row in consumed_materials: @@ -357,14 +353,10 @@ 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"), - ) - if voucher_nos - else {} + 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"), ) for row in transferred_items: diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index e7637aca63eac..00a308aac52f2 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -1948,6 +1948,9 @@ def get_available_batches(kwargs): # For work order and subcontracting def get_voucher_wise_serial_batch_from_bundle(**kwargs) -> dict[str, dict]: + if kwargs.get("voucher_nos") == []: + return {} + data = get_ledgers_from_serial_batch_bundle(**kwargs) if not data: return {}