feat: cards, attributes and modules

This commit is contained in:
2025-02-19 14:46:31 +04:00
parent a509a3a586
commit 1af78ce08a
61 changed files with 3212 additions and 2795 deletions

View File

@@ -1,24 +1,24 @@
from typing import TypedDict, List, Dict, Tuple, Optional
from models import DealProduct, Deal, DealStatusHistory
from models import CardProduct, Card, CardStatusHistory
class DealTechSpecProductData(TypedDict):
deal: Deal
last_status: DealStatusHistory
deal: Card
last_status: CardStatusHistory
total_one_product: int
quantity: int
additional_info: Optional[str]
# Поле для группировки товаров с одним артикулом и вывода таблицы [Штрихкод, Размер, Кол-во, Короба]
deal_products: List[DealProduct]
deal_products: List[CardProduct]
# Поле для группировки товаров из нескольких сделок и вывода таблицы [Склад отгрузки, Кол-во]
warehouses_and_quantities: List[Tuple[str, int]]
class DealTechSpecData(TypedDict):
deals: List[Deal]
deals: List[Card]
products: Dict[str, DealTechSpecProductData]
product_images: Tuple
deal_ids_header: str

View File

@@ -8,13 +8,13 @@ from weasyprint import HTML, CSS
from constants import DEAL_STATUS_STR, ENV, APP_PATH
from generators.deal_pdf_generator.deal_data import DealTechSpecProductData, DealTechSpecData
from models import Deal, DealProduct, DealService as DealServiceModel, Product, DealGroup
from services.deal_group import DealGroupService
from models import Card, CardProduct, CardService as DealServiceModel, Product, CardGroup
from services.card_group import CardGroupService
from utils.images_fetcher import fetch_images
# Генерация ключа для группировки deal_product по артикулу и услугам
def _gen_key_for_product(deal_product: DealProduct) -> str:
def _gen_key_for_product(deal_product: CardProduct) -> str:
return f"{deal_product.product.article} - " + ",".join(
str(service.service_id) for service in deal_product.services
)
@@ -48,10 +48,10 @@ class DealTechSpecPdfGenerator:
"deal_ids_header": "",
"deal_status_str": DEAL_STATUS_STR,
}
self.deal: Deal
self.deal: Card
@staticmethod
async def _group_deal_products_by_products(deal_products: List[DealProduct]) -> Dict[str, DealTechSpecProductData]:
async def _group_deal_products_by_products(deal_products: List[CardProduct]) -> Dict[str, DealTechSpecProductData]:
products: Dict[str, DealTechSpecProductData] = {}
additional_info: Optional[str]
@@ -61,7 +61,7 @@ class DealTechSpecPdfGenerator:
if key not in products:
products[key] = {
"deal": deal_product.deal,
"deal": deal_product.card,
"deal_products": [deal_product],
"quantity": deal_product.quantity,
"additional_info": deal_product.product.additional_info,
@@ -75,18 +75,18 @@ class DealTechSpecPdfGenerator:
return products
async def _get_deal_by_id(self, deal_id: int) -> Optional[Deal]:
deal: Deal | None = await self._session.scalar(
select(Deal)
.where(Deal.id == deal_id)
async def _get_deal_by_id(self, deal_id: int) -> Optional[Card]:
deal: Card | None = await self._session.scalar(
select(Card)
.where(Card.id == deal_id)
.options(
selectinload(Deal.products).selectinload(DealProduct.services),
selectinload(Deal.products).selectinload(DealProduct.product).selectinload(Product.barcodes),
selectinload(Deal.services).selectinload(DealServiceModel.service),
selectinload(Deal.status_history),
selectinload(Deal.group).selectinload(DealGroup.deals),
joinedload(Deal.client),
joinedload(Deal.shipping_warehouse),
selectinload(Card.products).selectinload(CardProduct.services),
selectinload(Card.products).selectinload(CardProduct.product).selectinload(Product.barcodes),
selectinload(Card.services).selectinload(DealServiceModel.service),
selectinload(Card.status_history),
selectinload(Card.group).selectinload(CardGroup.cards),
joinedload(Card.client),
joinedload(Card.shipping_warehouse),
)
)
return deal
@@ -94,7 +94,7 @@ class DealTechSpecPdfGenerator:
def _set_deals_ids_header(self):
self.deal_doc["deal_ids_header"] = f"ID: {self.deal.id}"
if self.deal.group:
self.deal_doc["deal_ids_header"] = "ID: " + ", ".join(str(d.id) for d in self.deal.group.deals)
self.deal_doc["deal_ids_header"] = "ID: " + ", ".join(str(d.id) for d in self.deal.group.cards)
async def _create_deal_tech_spec_document_html(self, deal_id: int):
deal = await self._get_deal_by_id(deal_id)
@@ -105,7 +105,7 @@ class DealTechSpecPdfGenerator:
self._set_deals_ids_header()
if deal.group:
deals = await DealGroupService(self._session).get_deals_by_group_id(deal.group.id)
deals = await CardGroupService(self._session).get_cards_by_group_id(deal.group.id)
for d in deals:
self.deal_doc["deals"].append(d)
grouped_products = await self._group_deal_products_by_products(d.products)

View File

@@ -42,7 +42,7 @@ class PriceListPdfGenerator:
# Определяем функцию сортировки категорий по рангу
def category_sort_key(category):
if service_type == ServiceType.DEAL_SERVICE:
return category.deal_service_rank
return category.card_service_rank
else:
return category.product_service_rank

View File

@@ -63,7 +63,7 @@ class ServiceExcelExporter:
categories = {service.category for services in categories_dict.values() for service in services}
def category_sort_key(category):
return category.deal_service_rank if service_type == ServiceType.DEAL_SERVICE else category.product_service_rank
return category.card_service_rank if service_type == ServiceType.DEAL_SERVICE else category.product_service_rank
sorted_categories = sorted(categories, key=category_sort_key)
sorted_categories_dict = {category.id: categories_dict[category.id] for category in sorted_categories}

View File

@@ -11,18 +11,18 @@ from sqlalchemy.orm import joinedload, selectinload
from constants import DOMAIN_NAME
from generators.base_pdf_card_generator.base_pdf_card_generator import BasePdfCardGenerator
from models import Deal, ShippingWarehouse, Pallet
from models import Card, ShippingWarehouse, Pallet
from models.shipping import Box
class ShippingQRCodeGenerator(BasePdfCardGenerator):
async def _get_deal_by_id(self, deal_id: int) -> Optional[Deal]:
async def _get_deal_by_id(self, deal_id: int) -> Optional[Card]:
stmt = (
select(Deal)
.where(Deal.id == deal_id)
select(Card)
.where(Card.id == deal_id)
.options(
joinedload(Deal.shipping_warehouse),
selectinload(Deal.pallets),
joinedload(Card.shipping_warehouse),
selectinload(Card.pallets),
)
)
deal = (await self._session.execute(stmt)).one_or_none()
@@ -93,7 +93,7 @@ class ShippingQRCodeGenerator(BasePdfCardGenerator):
func.count(Box.id).label("box_count"),
)
.join(Box, isouter=True)
.where(Pallet.deal_id == deal_id)
.where(Pallet.card_id == deal_id)
.group_by(Pallet.id)
)
pallets = (await self._session.execute(stmt_boxes_on_pallets)).all()