diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index d984d6eb996..494fb3b8bb2 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -465,9 +465,11 @@ class Item(Document): def validate_duplicate_product_bundles_before_merge(self, old_name, new_name): "Block merge if both old and new items have product bundles." - bundle = frappe.get_value("Product Bundle",filters={"new_item_code": old_name}) - if bundle: - bundle_link = get_link_to_form("Product Bundle", bundle) + old_bundle = frappe.get_value("Product Bundle",filters={"new_item_code": old_name}) + new_bundle = frappe.get_value("Product Bundle",filters={"new_item_code": new_name}) + + if old_bundle and new_bundle: + bundle_link = get_link_to_form("Product Bundle", old_bundle) old_name, new_name = frappe.bold(old_name), frappe.bold(new_name) msg = _("Please delete Product Bundle {0}, before merging {1} into {2}").format( diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py index 6f5f1ff786a..9491e172593 100644 --- a/erpnext/stock/doctype/item/test_item.py +++ b/erpnext/stock/doctype/item/test_item.py @@ -397,6 +397,7 @@ class TestItem(ERPNextTestCase): create_item("Test Item inside Bundle") bundle_items = ["Test Item inside Bundle"] + # make bundles for both items bundle1 = make_product_bundle("Test Item Bundle Item 1", bundle_items, qty=2) make_product_bundle("Test Item Bundle Item 2", bundle_items, qty=2)