From acfdce6aded91b830b773ce84b08da47d44be790 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 30 Apr 2015 11:50:27 +0530 Subject: [PATCH] Removed duplicate item validation --- .../purchase_common/purchase_common.py | 32 ++++--------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.py b/erpnext/buying/doctype/purchase_common/purchase_common.py index 2cf8673dc5..25f429a1c5 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.py +++ b/erpnext/buying/doctype/purchase_common/purchase_common.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import frappe -from frappe.utils import flt +from frappe.utils import flt, cstr from frappe import _ from erpnext.stock.doctype.item.item import get_last_purchase_details @@ -64,7 +64,7 @@ class PurchaseCommon(BuyingController): = d.rate = item_last_purchase_rate def validate_for_items(self, obj): - check_list, chk_dupl_itm=[],[] + items = [] for d in obj.get(obj.fname): # validation for valid qty if flt(d.qty) < 0 or (d.parenttype != 'Purchase Receipt' and not flt(d.qty)): @@ -96,30 +96,10 @@ class PurchaseCommon(BuyingController): if item[0][1] != 'Yes' and item[0][2] != 'Yes': frappe.throw(_("{0} must be a Purchased or Sub-Contracted Item in row {1}").format(d.item_code, d.idx)) - # list criteria that should not repeat if item is stock item - e = [getattr(d, "schedule_date", None), d.item_code, d.description, d.warehouse, d.uom, - d.meta.get_field('prevdoc_docname') and d.prevdoc_docname or d.meta.get_field('sales_order_no') and d.sales_order_no or '', - d.meta.get_field('prevdoc_detail_docname') and d.prevdoc_detail_docname or '', - d.meta.get_field('batch_no') and d.batch_no or ''] - - # if is not stock item - f = [getattr(d, "schedule_date", None), d.item_code, d.description] - - ch = frappe.db.sql("""select is_stock_item from `tabItem` where name = %s""", d.item_code) - - if ch and ch[0][0] == 'Yes': - # check for same items - if e in check_list: - frappe.throw(_("Item {0} has been entered multiple times with same description or date or warehouse").format(d.item_code)) - else: - check_list.append(e) - - elif ch and ch[0][0] == 'No': - # check for same items - if f in chk_dupl_itm: - frappe.throw(_("Item {0} has been entered multiple times with same description or date").format(d.item_code)) - else: - chk_dupl_itm.append(f) + items.append(cstr(d.item_code)) + if items and len(items) != len(set(items)): + frappe.msgprint(_("Warning: Same item has been entered multiple times.")) + def check_for_stopped_status(self, doctype, docname): stopped = frappe.db.sql("""select name from `tab%s` where name = %s and