Skip to content

Commit

Permalink
fix: strip html tags before checking for empty description
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Apr 7, 2022
1 parent 8e42525 commit 573523e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 2 additions & 5 deletions erpnext/stock/doctype/item/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
now_datetime,
nowtime,
strip,
strip_html,
)
from frappe.utils.html_utils import clean_html

Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions erpnext/stock/doctype/item/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<p></p>"})
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")
Expand Down

0 comments on commit 573523e

Please sign in to comment.