Merge branch 'develop' into fix-account-selection-gst-settings

This commit is contained in:
Afshan 2021-07-05 21:35:23 +05:30 committed by GitHub
commit 668da102c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -1100,6 +1100,8 @@ def make_variant_bom(source_name, bom_no, item, variant_items, target_doc=None):
},
'BOM Item': {
'doctype': 'BOM Item',
# stop get_mapped_doc copying parent bom_no to children
'field_no_map': ['bom_no'],
'condition': lambda doc: doc.has_variants == 0
},
}, target_doc, postprocess)

View File

@ -8,6 +8,7 @@ import frappe
from frappe.utils import cstr, flt
from frappe.test_runner import make_test_records
from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import create_stock_reconciliation
from erpnext.manufacturing.doctype.bom.bom import make_variant_bom
from erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool import update_cost
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
@ -248,6 +249,37 @@ class TestBOM(unittest.TestCase):
for reqd_item, created_item in zip(reqd_order, created_order):
self.assertEqual(reqd_item, created_item.item_code)
def test_generated_variant_bom(self):
from erpnext.controllers.item_variant import create_variant
template_item = make_item(
"_TestTemplateItem", {"has_variants": 1, "attributes": [{"attribute": "Test Size"},]}
)
variant = create_variant(template_item.item_code, {"Test Size": "Large"})
variant.insert(ignore_if_duplicate=True)
bom_tree = {
template_item.item_code: {
"SubAssembly1": {"ChildPart1": {}, "ChildPart2": {},},
"ChildPart5": {},
}
}
template_bom = create_nested_bom(bom_tree, prefix="")
variant_bom = make_variant_bom(
template_bom.name, template_bom.name, variant.item_code, variant_items=[]
)
variant_bom.save()
reqd_order = template_bom.get_tree_representation().level_order_traversal()
created_order = variant_bom.get_tree_representation().level_order_traversal()
self.assertEqual(len(reqd_order), len(created_order))
for reqd_item, created_item in zip(reqd_order, created_order):
self.assertEqual(reqd_item.item_code, created_item.item_code)
self.assertEqual(reqd_item.qty, created_item.qty)
self.assertEqual(reqd_item.exploded_qty, created_item.exploded_qty)
def get_default_bom(item_code="_Test FG Item 2"):
return frappe.db.get_value("BOM", {"item": item_code, "is_active": 1, "is_default": 1})