feat: new barcodes
This commit is contained in:
@@ -2,6 +2,7 @@ from sqlalchemy import select, update, insert
|
||||
from sqlalchemy.orm import selectinload, joinedload
|
||||
|
||||
from barcodes.attributes import AttributeWriterFactory
|
||||
from barcodes.generator.default_generator import DefaultBarcodeGenerator
|
||||
from models import BarcodeTemplate, BarcodeTemplateAttribute, barcode_template_attribute_link, Product, \
|
||||
BarcodeTemplateAdditionalField, BarcodeTemplateSize
|
||||
from schemas.barcode import *
|
||||
@@ -73,6 +74,30 @@ class BarcodeService(BaseService):
|
||||
)
|
||||
return GetProductBarcodeResponse(barcode=barcode)
|
||||
|
||||
async def get_barcode_pdf(self, request: GetProductBarcodePdfRequest) -> GetProductBarcodeResponse:
|
||||
# get product by id
|
||||
stmt = (
|
||||
select(Product)
|
||||
.options(
|
||||
joinedload(Product.client)
|
||||
)
|
||||
.filter(Product.id == request.product_id)
|
||||
)
|
||||
query = await self.session.execute(stmt)
|
||||
product: Product = query.scalar()
|
||||
if not product:
|
||||
raise ValueError('Товар не найден')
|
||||
barcode_template = await self._get_barcode_template(request, product)
|
||||
default_generator = DefaultBarcodeGenerator()
|
||||
filename = f'{product.id}_barcode.pdf'
|
||||
pdf_buffer = default_generator.generate(
|
||||
request.barcode,
|
||||
product,
|
||||
barcode_template,
|
||||
request.quantity
|
||||
)
|
||||
return filename, pdf_buffer
|
||||
|
||||
# endregion
|
||||
|
||||
# region Template
|
||||
|
||||
Reference in New Issue
Block a user