From 16862f905191f0610bcf835a7402dbc16c91e512 Mon Sep 17 00:00:00 2001 From: joezsweet Date: Fri, 16 Feb 2018 13:03:30 +0100 Subject: [PATCH] Better handling of auto set barcode_type issue (#12970) Get barcode_type options and check if value is included --- erpnext/stock/doctype/item/item.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 4b97fa3d44..1c85ecd4e2 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -483,6 +483,7 @@ class Item(WebsiteGenerator): from stdnum import ean if len(self.barcodes) > 0: for item_barcode in self.barcodes: + options = frappe.get_meta("Item Barcode").get_options("barcode_type").split() if item_barcode.barcode: duplicate = frappe.db.sql( """select parent from `tabItem Barcode` where barcode = %s and parent != %s""", (item_barcode.barcode, self.name)) @@ -490,7 +491,7 @@ class Item(WebsiteGenerator): frappe.throw(_("Barcode {0} already used in Item {1}").format( item_barcode.barcode, duplicate[0][0])) - item_barcode.barcode_type = "" if item_barcode.barcode_type not in ["EAN", "UPC-A"] else item_barcode.barcode_type + item_barcode.barcode_type = "" if item_barcode.barcode_type not in options else 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(