fix: Pick Template BOM if variant BOM absent in WO popup from SO

- Use `get_default_bom` in sales_order.py (reduce duplicate utility functions)
- Remove redundant if else in `get_work_order_items`
- `get_default_bom`: If no BOM and template exists try to fetch template BOM
- test: `get_work_order_items` via SO and if right BOM is picked
This commit is contained in:
marination
2022-06-14 17:20:44 +05:30
parent f8011f30e0
commit 9f2d325e67
3 changed files with 83 additions and 38 deletions

View File

@@ -1352,12 +1352,22 @@ def get_price_list_currency_and_exchange_rate(args):
@frappe.whitelist()
def get_default_bom(item_code=None):
if item_code:
bom = frappe.db.get_value(
"BOM", {"docstatus": 1, "is_default": 1, "is_active": 1, "item": item_code}
def _get_bom(item):
bom = frappe.get_all(
"BOM", dict(item=item, is_active=True, is_default=True, docstatus=1), limit=1
)
if bom:
return bom
return bom[0].name if bom else None
if not item_code:
return
bom_name = _get_bom(item_code)
template_item = frappe.db.get_value("Item", item_code, "variant_of")
if not bom_name and template_item:
bom_name = _get_bom(template_item)
return bom_name
@frappe.whitelist()