feat(stock): Support more barcodes in an item by validate the barcode with the barcodenumber module (#33863)

feat(stock): Support more barcodes in an article by validate the barcode with the barcodenumber module
This commit is contained in:
Johannes Obermeier 2023-02-19 15:06:05 +01:00 committed by GitHub
parent c722f2819c
commit 2a90fad710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 15 deletions

View File

@ -358,7 +358,7 @@ class Item(Document):
check_list.append(d.item_tax_template)
def validate_barcode(self):
from stdnum import ean
import barcodenumber
if len(self.barcodes) > 0:
for item_barcode in self.barcodes:
@ -376,19 +376,16 @@ class Item(Document):
item_barcode.barcode_type = (
"" if item_barcode.barcode_type not in options else item_barcode.barcode_type
)
if item_barcode.barcode_type and item_barcode.barcode_type.upper() in (
"EAN",
"UPC-A",
"EAN-13",
"EAN-8",
):
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
),
InvalidBarcode,
)
if item_barcode.barcode_type:
barcode_type = convert_erpnext_to_barcodenumber(item_barcode.barcode_type.upper())
if barcode_type in barcodenumber.barcodes():
if not barcodenumber.check_code(barcode_type, item_barcode.barcode):
frappe.throw(
_("Barcode {0} is not a valid {1} code").format(
item_barcode.barcode, item_barcode.barcode_type
),
InvalidBarcode,
)
def validate_warehouse_for_reorder(self):
"""Validate Reorder level table for duplicate and conditional mandatory"""
@ -985,6 +982,22 @@ class Item(Document):
)
def convert_erpnext_to_barcodenumber(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
def make_item_price(item, price_list_name, item_price):
frappe.get_doc(
{

View File

@ -579,6 +579,19 @@ class TestItem(FrappeTestCase):
{
"barcode": "ARBITRARY_TEXT",
},
{"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": "0123456789012", "barcode_type": "GS1"},
{"barcode": "2211564566668", "barcode_type": "GTIN"},
{"barcode": "0256480249", "barcode_type": "ISBN"},
{"barcode": "0192552570", "barcode_type": "ISBN-10"},
{"barcode": "9781234567897", "barcode_type": "ISBN-13"},
{"barcode": "9771234567898", "barcode_type": "ISSN"},
{"barcode": "4581171967072", "barcode_type": "JAN"},
{"barcode": "12345678", "barcode_type": "PZN"},
{"barcode": "725272730706", "barcode_type": "UPC"},
]
create_item(item_code)
for barcode_properties in barcode_properties_list:

View File

@ -25,7 +25,7 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Barcode Type",
"options": "\nEAN\nUPC-A"
"options": "\nEAN\nUPC-A\nCODE-39\nEAN-12\nEAN-8\nGS1\nGTIN\nISBN\nISBN-10\nISBN-13\nISSN\nJAN\nPZN\nUPC"
},
{
"fieldname": "uom",

View File

@ -12,6 +12,7 @@ dependencies = [
"pycountry~=20.7.3",
"python-stdnum~=1.16",
"Unidecode~=1.2.0",
"barcodenumber~=0.5.0",
# integration dependencies
"gocardless-pro~=1.22.0",