From 43372d3333ab80d8348b4d375cbbb7dd6e74a149 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Sun, 10 Dec 2017 20:56:48 +0100 Subject: [PATCH] - make barcode mandatory if child row is added - check valid barcode only if exists --- erpnext/stock/doctype/item/item.py | 17 +++++++++-------- .../doctype/item_barcode/item_barcode.json | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index a6af44bd73..683679303b 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -486,15 +486,16 @@ class Item(WebsiteGenerator): from stdnum import ean if len(self.barcodes) > 0: for item_barcode in self.barcodes: - duplicate = frappe.db.sql("""select parent from `tabItem Barcode` where barcode = %s and parent != %s""", (item_barcode.barcode, self.name)) - if duplicate: - frappe.throw(_("Barcode {0} already used in Item {1}").format( - item_barcode.barcode, duplicate[0][0])) + if item_barcode.barcode: + duplicate = frappe.db.sql("""select parent from `tabItem Barcode` where barcode = %s and parent != %s""", (item_barcode.barcode, self.name)) + if duplicate: + frappe.throw(_("Barcode {0} already used in Item {1}").format( + item_barcode.barcode, duplicate[0][0])) - if item_barcode.barcode_type: - if not ean.is_valid(item_barcode.barcode): - frappe.throw(_("Barcode {0} is not a valid {1} code").format( - item_barcode.barcode, item_barcode.barcode_type)) + if item_barcode.barcode_type: + if not ean.is_valid(item_barcode.barcode): + frappe.throw(_("Barcode {0} is not a valid {1} code").format( + item_barcode.barcode, item_barcode.barcode_type)) def validate_warehouse_for_reorder(self): '''Validate Reorder level table for duplicate and conditional mandatory''' diff --git a/erpnext/stock/doctype/item_barcode/item_barcode.json b/erpnext/stock/doctype/item_barcode/item_barcode.json index e592981160..c8a3a897b3 100644 --- a/erpnext/stock/doctype/item_barcode/item_barcode.json +++ b/erpnext/stock/doctype/item_barcode/item_barcode.json @@ -38,7 +38,7 @@ "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, - "reqd": 0, + "reqd": 1, "search_index": 0, "set_only_once": 0, "unique": 1 @@ -85,7 +85,7 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2017-12-10 19:45:08.634821", + "modified": "2017-12-10 20:55:23.814039", "modified_by": "Administrator", "module": "Stock", "name": "Item Barcode",