From 7b1b3f0fa8351d992ead2d4328debff72a899c51 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Mon, 30 Sep 2019 11:01:05 +0530 Subject: [PATCH] fix: Allow alternative item in stock entry while transfering material to subcontractor (#19189) --- erpnext/stock/doctype/stock_entry/stock_entry.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index b810e3594c..69c624b7a7 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -539,6 +539,21 @@ class StockEntry(StockController): total_allowed = required_qty + (required_qty * (qty_allowance/100)) + if not required_qty: + bom_no = frappe.db.get_value("Purchase Order Item", + {"parent": self.purchase_order, "item_code": se_item.subcontracted_item}, + "bom") + + allow_alternative_item = frappe.get_value("BOM", bom_no, "allow_alternative_item") + + if allow_alternative_item: + original_item_code = frappe.get_value("Item Alternative", {"alternative_item_code": item_code}, "item_code") + + required_qty = sum([flt(d.required_qty) for d in purchase_order.supplied_items \ + if d.rm_item_code == original_item_code]) + + total_allowed = required_qty + (required_qty * (qty_allowance/100)) + if not required_qty: frappe.throw(_("Item {0} not found in 'Raw Materials Supplied' table in Purchase Order {1}") .format(se_item.item_code, self.purchase_order))