Electronic stock management. -- not updated anymore
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
 

53 lines
1.4 KiB

from exceptions import ValueError
import barcode
from barcode.writer import ImageWriter
import os
BC_SIZES = {
"normal": (10.0, 10),
"medium": (5.0, 10),
"mini": (2.0, 8),
"mini_notext": (2.0, 0)
}
def generate_ean13(part_type, part_id, dir_out):
"""
00 category ID
.. 000 000 000 00 part number
-----------------
00 000 000 000 00
"""
_type = "%s" % part_type
_type = _type.zfill(2)
_id = "%s" % part_id
barcode_str = "{0}".format(_type)
barcode_str += _id.zfill(11)
if len(barcode_str) > 13:
raise ValueError("barcode length exceded 13")
dir_output = os.path.join(dir_out, "barcodes")
def generate(txt, size):
opts = dict(module_width=0.2, module_height=size[0], quiet_zone=1, font_size=size[1], text_distance=1)
ean = barcode.get('ean13', barcode_str, writer=ImageWriter())
out = os.path.join(dir_output, _type, "{0}_{1}".format(txt, barcode_str))
if not os.path.isdir(os.path.join(dir_output, _type)):
os.makedirs(os.path.join(dir_output, _type))
ean.save(out, opts)
generate('normal', BC_SIZES['normal'])
generate('medium', BC_SIZES['medium'])
generate('mini', BC_SIZES['mini'])
generate('mini_notext', BC_SIZES['mini_notext'])
return {"Barcode": barcode_str,
"Out": dir_output,
"Status": "OK",
"Size": len(barcode_str),
"GeneratedSizes": ['normal', 'mini']}