fix: strip html tags before checking for empty description (#30619)

This commit is contained in:
Ankush Menat 2022-04-07 12:53:10 +05:30 committed by GitHub
parent 8e425252c4
commit e4c6d6a1a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -18,6 +18,7 @@ from frappe.utils import (
now_datetime, now_datetime,
nowtime, nowtime,
strip, strip,
strip_html,
) )
from frappe.utils.html_utils import clean_html from frappe.utils.html_utils import clean_html
@ -69,10 +70,6 @@ class Item(Document):
self.item_code = strip(self.item_code) self.item_code = strip(self.item_code)
self.name = 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): def after_insert(self):
"""set opening stock and item price""" """set opening stock and item price"""
if self.standard_rate: if self.standard_rate:
@ -86,7 +83,7 @@ class Item(Document):
if not self.item_name: if not self.item_name:
self.item_name = self.item_code self.item_name = self.item_code
if not self.description: if not strip_html(cstr(self.description)).strip():
self.description = self.item_name self.description = self.item_name
self.validate_uom() self.validate_uom()

View File

@ -744,6 +744,13 @@ class TestItem(FrappeTestCase):
self.assertTrue(get_data(warehouse="_Test Warehouse - _TC")) self.assertTrue(get_data(warehouse="_Test Warehouse - _TC"))
self.assertTrue(get_data(item_group="All Item Groups")) 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): def set_item_variant_settings(fields):
doc = frappe.get_doc("Item Variant Settings") doc = frappe.get_doc("Item Variant Settings")