From e4c6d6a1a6b9d9ed9aa01d9f3290546bfa76e4bb Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 7 Apr 2022 12:53:10 +0530 Subject: [PATCH] fix: strip html tags before checking for empty description (#30619) --- erpnext/stock/doctype/item/item.py | 7 ++----- erpnext/stock/doctype/item/test_item.py | 7 +++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 535f56520965..5fdecc9895ad 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -18,6 +18,7 @@ now_datetime, nowtime, strip, + strip_html, ) from frappe.utils.html_utils import clean_html @@ -69,10 +70,6 @@ def autoname(self): self.item_code = strip(self.item_code) self.name = self.item_code - def before_insert(self): - if not self.description: - self.description = self.item_name - def after_insert(self): """set opening stock and item price""" if self.standard_rate: @@ -86,7 +83,7 @@ def validate(self): if not self.item_name: self.item_name = self.item_code - if not self.description: + if not strip_html(cstr(self.description)).strip(): self.description = self.item_name self.validate_uom() diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py index 328d937f3186..8dd35d769f95 100644 --- a/erpnext/stock/doctype/item/test_item.py +++ b/erpnext/stock/doctype/item/test_item.py @@ -744,6 +744,13 @@ def test_item_dashboard(self): self.assertTrue(get_data(warehouse="_Test Warehouse - _TC")) self.assertTrue(get_data(item_group="All Item Groups")) + def test_empty_description(self): + item = make_item(properties={"description": "

"}) + self.assertEqual(item.description, item.item_name) + item.description = "" + item.save() + self.assertEqual(item.description, item.item_name) + def set_item_variant_settings(fields): doc = frappe.get_doc("Item Variant Settings")