Skip to content

Commit

Permalink
fix: TypeError: 'float' object is not iterable (frappe#41758)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Jun 4, 2024
1 parent a8fc32d commit cf508ce
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
1 change: 1 addition & 0 deletions erpnext/manufacturing/doctype/bom_creator/bom_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
49 changes: 28 additions & 21 deletions erpnext/stock/report/stock_ledger/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]:
Expand All @@ -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)
Expand Down

0 comments on commit cf508ce

Please sign in to comment.