feat: new barcodes
This commit is contained in:
@@ -1,10 +1,26 @@
|
||||
from barcodes.attributes import AttributeWriterFactory
|
||||
from barcodes.generator.base import BaseBarcodeGenerator
|
||||
from barcodes.pdf import PDFGenerator
|
||||
from models import ProductBarcode, Product, BarcodeTemplate
|
||||
|
||||
|
||||
class DefaultBarcodeGenerator(BaseBarcodeGenerator):
|
||||
def generate(self,
|
||||
barcode: ProductBarcode,
|
||||
barcode: str,
|
||||
product: Product,
|
||||
template: BarcodeTemplate):
|
||||
pass
|
||||
template: BarcodeTemplate,
|
||||
quantity: int = 1):
|
||||
pdf_generator = PDFGenerator()
|
||||
attributes = {}
|
||||
for attribute in template.attributes:
|
||||
attribute_getter = AttributeWriterFactory.get_writer(attribute.key)
|
||||
if not attribute_getter:
|
||||
continue
|
||||
value = attribute_getter.get_value(product)
|
||||
if not value:
|
||||
continue
|
||||
attributes[attribute.name] = value
|
||||
for additional_attribute in template.additional_attributes:
|
||||
attributes[additional_attribute.name] = additional_attribute.value
|
||||
barcode_text = '<br/>'.join([f'{key}: {value}' for key, value in attributes.items()])
|
||||
return pdf_generator.generate(barcode, barcode_text, num_duplicates=quantity)
|
||||
|
||||
Reference in New Issue
Block a user