fix(bom): allow zero qty for secondary items (Co-Product, By-Product, Scrap, Additional Finished Good)

Secondary output items in a BOM do not always guarantee output during
manufacture. The actual qty is only known when manufacturing completes,
so setting zero in the BOM is a valid way to express "output is
non-deterministic".

Changes:
- Remove `reqd: 1` from the qty field in BOM Secondary Item so that 0
  is accepted as an explicit value (non_negative constraint is kept, so
  negative values are still rejected).
- Relax validate_secondary_items() in bom.py to only reject qty that is
  None/missing, not qty that is explicitly 0.
- Add a qty event handler in bom.js that shows a blue informational
  alert when the user sets qty to 0, explaining that the actual output
  will be recorded at manufacture time.

Fixes https://github.com/frappe/erpnext/issues/55401

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
(cherry picked from commit 6771daf6a1)

# Conflicts:
#	erpnext/manufacturing/doctype/bom/bom.py
This commit is contained in:
Umair Sayed
2026-06-12 14:45:02 +05:30
committed by Mergify
parent 0326793355
commit 7d95acabe7
3 changed files with 20 additions and 3 deletions

View File

@@ -1012,6 +1012,19 @@ frappe.ui.form.on("BOM Secondary Item", {
item_code(frm, cdt, cdn) {
const { item_code } = locals[cdt][cdn];
},
qty(frm, cdt, cdn) {
const row = locals[cdt][cdn];
if (flt(row.qty) === 0) {
frappe.show_alert({
message: __(
"Row #{0}: Qty is set to zero for {1}. The actual output will be entered at the time of manufacture.",
[row.idx, frappe.bold(row.item_code)]
),
indicator: "blue",
});
}
},
});
function trigger_process_loss_qty_prompt(frm, cdt, cdn, item_code) {

View File

@@ -341,10 +341,15 @@ class BOM(WebsiteGenerator):
).format(item.idx, get_link_to_form("Item", item.item_code))
)
if not item.qty:
if item.qty is None:
frappe.throw(
<<<<<<< HEAD
_("Row #{0}: Quantity should be greater than 0 for {1} Item {2}").format(
item.idx, item.type, get_link_to_form("Item", item.item_code)
=======
_("Row #{0}: Quantity is required for {1} Item {2}").format(
item.idx, item.secondary_item_type, get_link_to_form("Item", item.item_code)
>>>>>>> 6771daf6a1 (fix(bom): allow zero qty for secondary items (Co-Product, By-Product, Scrap, Additional Finished Good))
)
)

View File

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