From a33f04ea41087305c95111aa86bf96d3df2e2b36 Mon Sep 17 00:00:00 2001 From: marination Date: Wed, 23 Feb 2022 16:26:20 +0530 Subject: [PATCH] fix: Check if both old and new items have bundles before merging - If only one has bundle against it, they can be merged --- erpnext/stock/doctype/item/item.py | 8 +++++--- erpnext/stock/doctype/item/test_item.py | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index d984d6eb99..494fb3b8bb 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 6f5f1ff786..9491e17259 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)