fix: incorrect EAN validation, EAN can be an EAN8, EAN12 or EAN13 code (#34250)
Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
This commit is contained in:
parent
fe672aa9b1
commit
70c78d0d67
@ -377,7 +377,9 @@ class Item(Document):
|
||||
"" if item_barcode.barcode_type not in options else item_barcode.barcode_type
|
||||
)
|
||||
if item_barcode.barcode_type:
|
||||
barcode_type = convert_erpnext_to_barcodenumber(item_barcode.barcode_type.upper())
|
||||
barcode_type = convert_erpnext_to_barcodenumber(
|
||||
item_barcode.barcode_type.upper(), item_barcode.barcode
|
||||
)
|
||||
if barcode_type in barcodenumber.barcodes():
|
||||
if not barcodenumber.check_code(barcode_type, item_barcode.barcode):
|
||||
frappe.throw(
|
||||
@ -982,20 +984,29 @@ class Item(Document):
|
||||
)
|
||||
|
||||
|
||||
def convert_erpnext_to_barcodenumber(erpnext_number):
|
||||
def convert_erpnext_to_barcodenumber(erpnext_number, barcode):
|
||||
if erpnext_number == "EAN":
|
||||
ean_type = {
|
||||
8: "EAN8",
|
||||
13: "EAN13",
|
||||
}
|
||||
barcode_length = len(barcode)
|
||||
if barcode_length in ean_type:
|
||||
return ean_type[barcode_length]
|
||||
|
||||
return erpnext_number
|
||||
|
||||
convert = {
|
||||
"UPC-A": "UPCA",
|
||||
"CODE-39": "CODE39",
|
||||
"EAN": "EAN13",
|
||||
"EAN-12": "EAN",
|
||||
"EAN-8": "EAN8",
|
||||
"ISBN-10": "ISBN10",
|
||||
"ISBN-13": "ISBN13",
|
||||
}
|
||||
|
||||
if erpnext_number in convert:
|
||||
return convert[erpnext_number]
|
||||
else:
|
||||
return erpnext_number
|
||||
|
||||
return erpnext_number
|
||||
|
||||
|
||||
def make_item_price(item, price_list_name, item_price):
|
||||
|
@ -581,8 +581,9 @@ class TestItem(FrappeTestCase):
|
||||
},
|
||||
{"barcode": "72527273070", "barcode_type": "UPC-A"},
|
||||
{"barcode": "123456", "barcode_type": "CODE-39"},
|
||||
{"barcode": "401268452363", "barcode_type": "EAN-12"},
|
||||
{"barcode": "90311017", "barcode_type": "EAN-8"},
|
||||
{"barcode": "401268452363", "barcode_type": "EAN"},
|
||||
{"barcode": "90311017", "barcode_type": "EAN"},
|
||||
{"barcode": "73513537", "barcode_type": "EAN"},
|
||||
{"barcode": "0123456789012", "barcode_type": "GS1"},
|
||||
{"barcode": "2211564566668", "barcode_type": "GTIN"},
|
||||
{"barcode": "0256480249", "barcode_type": "ISBN"},
|
||||
|
Loading…
Reference in New Issue
Block a user