Merge pull request #55852 from umairsy/fix/allow-zero-qty-bom-secondary-items

fix(bom): allow zero qty for secondary items in BOM
This commit is contained in:
Mihir Kandoi
2026-06-16 15:05:31 +05:30
committed by GitHub
3 changed files with 12 additions and 10 deletions

View File

@@ -373,13 +373,6 @@ class BOM(WebsiteGenerator):
).format(item.idx, get_link_to_form("Item", item.item_code))
)
if not item.qty:
frappe.throw(
_("Row #{0}: Quantity should be greater than 0 for {1} Item {2}").format(
item.idx, item.secondary_item_type, get_link_to_form("Item", item.item_code)
)
)
if item.process_loss_per >= 100:
frappe.throw(
_("Row #{0}: Process Loss Percentage should be less than 100% for {1} Item {2}").format(

View File

@@ -138,8 +138,7 @@
"fieldtype": "Float",
"in_list_view": 1,
"label": "Qty",
"non_negative": 1,
"reqd": 1
"non_negative": 1
},
{
"default": "0",

View File

@@ -554,6 +554,13 @@ class StockEntry(StockController, SubcontractingInwardController):
for d in self.get("items"):
if d.s_warehouse or d.set_basic_rate_manually:
continue
# Zero-qty secondary items carry no inventory value; skip rate calculation
if d.secondary_item_type and flt(d.transfer_qty) == 0:
d.basic_rate = 0.0
d.basic_amount = 0.0
continue
self._set_incoming_item_rate(d, outgoing_items_cost, raise_error_if_no_rate, zero_valuation_items)
if zero_valuation_items:
@@ -575,7 +582,10 @@ class StockEntry(StockController, SubcontractingInwardController):
cost_allocation_per = frappe.get_value(
"BOM Secondary Item", d.bom_secondary_item, "cost_allocation_per"
)
d.basic_rate = (outgoing_items_cost * (cost_allocation_per / 100)) / d.transfer_qty
# Only recalculate when cost is actually allocated; otherwise preserve the
# user-entered rate (or fall through to get_valuation_rate below)
if cost_allocation_per and flt(d.transfer_qty):
d.basic_rate = (outgoing_items_cost * (cost_allocation_per / 100)) / d.transfer_qty
if not d.basic_rate and not d.allow_zero_valuation_rate:
d.basic_rate = get_valuation_rate(