mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 19:59:12 +00:00
fix: Add null or empty checking to validation
This commit adds null or empty checking in the **Item Price** DocType's `check_duplicates()`. This was done to fix a bug where some prices are shown to be duplciates even though they aren't because they don't have values in some fields.
This commit is contained in:
@@ -48,20 +48,52 @@ class ItemPrice(Document):
|
|||||||
self.item_code,["item_name", "description"])
|
self.item_code,["item_name", "description"])
|
||||||
|
|
||||||
def check_duplicates(self):
|
def check_duplicates(self):
|
||||||
conditions = "where item_code=%(item_code)s and price_list=%(price_list)s and name != %(name)s"
|
conditions = """
|
||||||
|
where
|
||||||
|
item_code = %(item_code)s
|
||||||
|
and price_list = %(price_list)s
|
||||||
|
and name != %(name)s
|
||||||
|
"""
|
||||||
|
|
||||||
for field in ['uom', 'valid_from',
|
for field in [
|
||||||
'valid_upto', 'packing_unit', 'customer', 'supplier']:
|
"uom",
|
||||||
|
"valid_from",
|
||||||
|
"valid_upto",
|
||||||
|
"packing_unit",
|
||||||
|
"customer",
|
||||||
|
"supplier",
|
||||||
|
]:
|
||||||
if self.get(field):
|
if self.get(field):
|
||||||
conditions += " and {0} = %({1})s".format(field, field)
|
conditions += " and {0} = %({0})s ".format(field)
|
||||||
|
else:
|
||||||
|
conditions += """
|
||||||
|
and (
|
||||||
|
isnull({0})
|
||||||
|
or {0} = ''
|
||||||
|
)
|
||||||
|
""".format(
|
||||||
|
field
|
||||||
|
)
|
||||||
|
|
||||||
price_list_rate = frappe.db.sql("""
|
price_list_rate = frappe.db.sql(
|
||||||
SELECT price_list_rate
|
"""
|
||||||
FROM `tabItem Price`
|
select
|
||||||
{conditions} """.format(conditions=conditions), self.as_dict())
|
price_list_rate
|
||||||
|
from
|
||||||
|
`tabItem Price`
|
||||||
|
{conditions}
|
||||||
|
""".format(
|
||||||
|
conditions=conditions
|
||||||
|
),
|
||||||
|
self.as_dict(),
|
||||||
|
)
|
||||||
|
|
||||||
if price_list_rate :
|
if price_list_rate:
|
||||||
frappe.throw(_("Item Price appears multiple times based on Price List, Supplier/Customer, Currency, Item, UOM, Qty and Dates."), ItemPriceDuplicateItem)
|
frappe.throw(_("""
|
||||||
|
Item Price appears multiple times based on
|
||||||
|
Price List, Supplier/Customer, Currency, Item, UOM, Qty,
|
||||||
|
and Dates.
|
||||||
|
"""), ItemPriceDuplicateItem,)
|
||||||
|
|
||||||
def before_save(self):
|
def before_save(self):
|
||||||
if self.selling:
|
if self.selling:
|
||||||
|
|||||||
Reference in New Issue
Block a user