fix(manufacturing): case-sensitive variant BOM lookup on Postgres

_bom_contains_item() lowercased the item name and then reused that lowercased
value as a doc name in frappe.db.get_value("Item", item, "variant_of"). Doc
names are case-sensitive on Postgres, so the lowercased name matched no row,
variant_of came back NULL, and a Work Order for a variant item built from the
template's BOM was wrongly rejected with 'BOM ... does not belong to Item ...'.
Keep the original case for the Item lookup; the comparisons stay case-insensitive.
MariaDB is unchanged (its name lookup was case-insensitive either way).
This commit is contained in:
Mihir Kandoi
2026-06-21 15:29:16 +05:30
parent ed1261ef8d
commit 2e5310f8a0

View File

@@ -1402,16 +1402,18 @@ def validate_bom_no(item, bom_no):
def _bom_contains_item(bom, item):
item = item.lower()
item_lower = item.lower()
for d in bom.items:
if d.item_code.lower() == item:
if d.item_code.lower() == item_lower:
return True
for d in bom.secondary_items:
if d.item_code.lower() == item:
if d.item_code.lower() == item_lower:
return True
# Use the original-cased `item` for the Item lookup: names are case-sensitive on Postgres,
# so a lowercased name would miss the record and drop the variant->template BOM match.
return (
bom.item.lower() == item
bom.item.lower() == item_lower
or bom.item.lower() == cstr(frappe.db.get_value("Item", item, "variant_of")).lower()
)