feat: temp barcode templates
This commit is contained in:
@@ -1,20 +1,52 @@
|
||||
from sqlalchemy import select, update, insert
|
||||
from sqlalchemy.orm import selectinload
|
||||
from sqlalchemy.orm import selectinload, joinedload
|
||||
|
||||
from models import BarcodeTemplate, BarcodeTemplateAttribute, barcode_template_attribute_link
|
||||
from schemas.barcode import (GetBarcodeTemplateByIdRequest,
|
||||
GetBarcodeTemplateByIdResponse,
|
||||
BarcodeTemplateCreateResponse,
|
||||
BarcodeTemplateCreateRequest, CreateBarcodeTemplateAttributeRequest,
|
||||
BarcodeTemplateUpdateResponse, BarcodeTemplateUpdateRequest,
|
||||
BarcodeTemplateAttributeSchema, GetAllBarcodeTemplateAttributesResponse,
|
||||
GetAllBarcodeTemplatesResponse, BarcodeTemplateDeleteRequest,
|
||||
BarcodeTemplateDeleteResponse)
|
||||
from models import BarcodeTemplate, BarcodeTemplateAttribute, barcode_template_attribute_link, Product
|
||||
from schemas.barcode import *
|
||||
from services.base import BaseService
|
||||
|
||||
|
||||
class BarcodeService(BaseService):
|
||||
|
||||
# region Barcode
|
||||
async def get_barcode(self, request: GetProductBarcodeRequest) -> 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('Товар не найден')
|
||||
|
||||
# get barcode template by id
|
||||
if request.barcode_template_id:
|
||||
stmt = select(BarcodeTemplate).filter(BarcodeTemplate.id == request.barcode_template_id)
|
||||
query = await self.session.execute(stmt)
|
||||
barcode_template = query.scalar()
|
||||
if not barcode_template:
|
||||
raise ValueError('Шаблон не найден')
|
||||
elif product.barcode_template:
|
||||
barcode_template = product.barcode_template
|
||||
elif product.client.barcode_template:
|
||||
barcode_template = product.client.barcode_template
|
||||
else:
|
||||
stmt = select(BarcodeTemplate).filter(BarcodeTemplate.is_default == True)
|
||||
query = await self.session.execute(stmt)
|
||||
barcode_template = query.scalar()
|
||||
if not barcode_template:
|
||||
raise ValueError('Стандартный шаблон не найден')
|
||||
barcode_template: BarcodeTemplate
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
# endregion
|
||||
|
||||
# region Template
|
||||
async def get_barcode_template_by_id(self,
|
||||
request: GetBarcodeTemplateByIdRequest) -> GetBarcodeTemplateByIdResponse:
|
||||
|
||||
Reference in New Issue
Block a user