feat: cards, attributes and modules
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user