Skip to content

Commit

Permalink
fix: (patch) Fetch only BOMs with subassemblies for patch updation
Browse files Browse the repository at this point in the history
- Leaf BOMs won't have any 'From BOM' to add
- Added progress bar for feedback
  • Loading branch information
marination committed May 27, 2022
1 parent 09012d5 commit c6e9d6c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions erpnext/patches/v13_0/add_bom_reference_in_exploded_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@

def execute():
"Add 'From BOM' in exploded items rows to help updates without reset."
from erpnext.manufacturing.doctype.bom_update_log.bom_updation_utils import get_leaf_boms

leaf_boms = get_leaf_boms()

bom = frappe.qb.DocType("BOM")
bom_item = frappe.qb.DocType("BOM Item")
boms_with_children = (
frappe.qb.from_(bom_item)
.join(bom)
.on(bom_item.parent == bom.name)
.select(bom_item.parent)
.distinct()
.where((bom.is_active == 1) & (bom.docstatus == 1))
boms_with_sub_assembly_children = (
frappe.qb.from_(bom)
.select(bom.name)
.where((bom.name.notin(leaf_boms)) & (bom.is_active == 1) & (bom.docstatus == 1))
).run(as_dict=True)

for bom in boms_with_children:
bom = frappe.get_doc("BOM", bom.parent)
if not boms_with_sub_assembly_children:
return

total_count = len(boms_with_sub_assembly_children)
for count, bom in enumerate(boms_with_sub_assembly_children, start=1):
bom = frappe.get_doc("BOM", bom.name)
bom.update_exploded_items(save=True) # set 'From BOM' in exploded items

frappe.utils.update_progress_bar("Updating Exploded BOM Items ...", count, total_count)

0 comments on commit c6e9d6c

Please sign in to comment.