From cf508ce1edd05a2fe04eec0ea7cb6c6fca82fb0a Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Tue, 4 Jun 2024 11:58:32 +0530 Subject: [PATCH] fix: TypeError: 'float' object is not iterable (#41758) --- .../doctype/bom_creator/bom_creator.py | 1 + .../bom_configurator.bundle.js | 1 + .../stock/report/stock_ledger/stock_ledger.py | 49 +++++++++++-------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom_creator/bom_creator.py b/erpnext/manufacturing/doctype/bom_creator/bom_creator.py index 69455027f90..c84b300622c 100644 --- a/erpnext/manufacturing/doctype/bom_creator/bom_creator.py +++ b/erpnext/manufacturing/doctype/bom_creator/bom_creator.py @@ -562,6 +562,7 @@ def add_sub_assembly(**kwargs): "source_warehouse": bom_item.source_warehouse, "wip_warehouse": bom_item.wip_warehouse, "fg_warehouse": bom_item.fg_warehouse, + "skip_material_transfer": bom_item.skip_material_transfer, }, ) diff --git a/erpnext/public/js/bom_configurator/bom_configurator.bundle.js b/erpnext/public/js/bom_configurator/bom_configurator.bundle.js index f7531484fb2..d9cf3b1d17e 100644 --- a/erpnext/public/js/bom_configurator/bom_configurator.bundle.js +++ b/erpnext/public/js/bom_configurator/bom_configurator.bundle.js @@ -548,6 +548,7 @@ class BOMConfigurator { label: __("Is Subcontracted"), fieldname: "is_subcontracted", fieldtype: "Check", + hidden: node?.is_root || 0, default: data.is_subcontracted, }, { fieldtype: "Column Break" }, diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py index 2920ebf69e8..e56c499d767 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.py +++ b/erpnext/stock/report/stock_ledger/stock_ledger.py @@ -7,7 +7,7 @@ from collections import defaultdict import frappe from frappe import _ -from frappe.query_builder.functions import CombineDatetime +from frappe.query_builder.functions import CombineDatetime, Sum from frappe.utils import cint, flt from erpnext.stock.doctype.inventory_dimension.inventory_dimension import get_inventory_dimensions @@ -69,12 +69,12 @@ def execute(filters=None): stock_value += sle.stock_value_difference if sle.batch_no: if not batch_balance_dict.get(sle.batch_no): - batch_balance_dict[sle.batch_no] = 0 + batch_balance_dict[sle.batch_no] = [0, 0] - batch_balance_dict[sle.batch_no] += sle.actual_qty + batch_balance_dict[sle.batch_no][0] += sle.actual_qty if filters.get("segregate_serial_batch_bundle"): - actual_qty = batch_balance_dict[sle.batch_no] + actual_qty = batch_balance_dict[sle.batch_no][0] if sle.voucher_type == "Stock Reconciliation" and not sle.actual_qty: actual_qty = sle.qty_after_transaction @@ -530,7 +530,9 @@ def get_opening_balance_from_batch(filters, columns, sl_entries): query_filters = { "batch_no": filters.batch_no, "docstatus": 1, + "is_cancelled": 0, "posting_date": ("<", filters.from_date), + "company": filters.company, } for fields in ["item_code", "warehouse"]: @@ -547,25 +549,30 @@ def get_opening_balance_from_batch(filters, columns, sl_entries): if opening_data.get(field) is None: opening_data[field] = 0.0 - query_filters = [ - ["Serial and Batch Entry", "batch_no", "=", filters.batch_no], - ["Serial and Batch Bundle", "docstatus", "=", 1], - ["Serial and Batch Bundle", "posting_date", "<", filters.from_date], - ] - - for fields in ["item_code", "warehouse"]: - if filters.get(fields): - query_filters.append(["Serial and Batch Bundle", fields, "=", filters.get(fields)]) - - bundle_data = frappe.get_all( - "Serial and Batch Bundle", - fields=[ - "sum(`tabSerial and Batch Entry`.`qty`) as qty", - "sum(`tabSerial and Batch Entry`.`stock_value_difference`) as stock_value", - ], - filters=query_filters, + table = frappe.qb.DocType("Stock Ledger Entry") + sabb_table = frappe.qb.DocType("Serial and Batch Entry") + query = ( + frappe.qb.from_(table) + .inner_join(sabb_table) + .on(table.serial_and_batch_bundle == sabb_table.parent) + .select( + Sum(sabb_table.qty).as_("qty"), + Sum(sabb_table.stock_value_difference).as_("stock_value"), + ) + .where( + (sabb_table.batch_no == filters.batch_no) + & (sabb_table.docstatus == 1) + & (table.posting_date < filters.from_date) + & (table.is_cancelled == 0) + ) ) + for field in ["item_code", "warehouse", "company"]: + if filters.get(field): + query = query.where(table[field] == filters.get(field)) + + bundle_data = query.run(as_dict=True) + if bundle_data: opening_data.qty_after_transaction += flt(bundle_data[0].qty) opening_data.stock_value += flt(bundle_data[0].stock_value)