Merge pull request #34415 from s-aga-r/FIX-ISS-22-23-05720

fix: operation time for multi-level BOM in WO
This commit is contained in:
Sagar Sharma 2023-03-14 18:47:40 +05:30 committed by GitHub
commit e9f5ea6ede
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -31,7 +31,7 @@ class BOMTree:
# specifying the attributes to save resources # specifying the attributes to save resources
# ref: https://docs.python.org/3/reference/datamodel.html#slots # ref: https://docs.python.org/3/reference/datamodel.html#slots
__slots__ = ["name", "child_items", "is_bom", "item_code", "exploded_qty", "qty"] __slots__ = ["name", "child_items", "is_bom", "item_code", "qty", "exploded_qty", "bom_qty"]
def __init__( def __init__(
self, name: str, is_bom: bool = True, exploded_qty: float = 1.0, qty: float = 1 self, name: str, is_bom: bool = True, exploded_qty: float = 1.0, qty: float = 1
@ -50,9 +50,10 @@ class BOMTree:
def __create_tree(self): def __create_tree(self):
bom = frappe.get_cached_doc("BOM", self.name) bom = frappe.get_cached_doc("BOM", self.name)
self.item_code = bom.item self.item_code = bom.item
self.bom_qty = bom.quantity
for item in bom.get("items", []): for item in bom.get("items", []):
qty = item.qty / bom.quantity # quantity per unit qty = item.stock_qty / bom.quantity # quantity per unit
exploded_qty = self.exploded_qty * qty exploded_qty = self.exploded_qty * qty
if item.bom_no: if item.bom_no:
child = BOMTree(item.bom_no, exploded_qty=exploded_qty, qty=qty) child = BOMTree(item.bom_no, exploded_qty=exploded_qty, qty=qty)

View File

@ -682,7 +682,7 @@ class WorkOrder(Document):
for node in bom_traversal: for node in bom_traversal:
if node.is_bom: if node.is_bom:
operations.extend(_get_operations(node.name, qty=node.exploded_qty)) operations.extend(_get_operations(node.name, qty=node.exploded_qty / node.bom_qty))
bom_qty = frappe.get_cached_value("BOM", self.bom_no, "quantity") bom_qty = frappe.get_cached_value("BOM", self.bom_no, "quantity")
operations.extend(_get_operations(self.bom_no, qty=1.0 / bom_qty)) operations.extend(_get_operations(self.bom_no, qty=1.0 / bom_qty))