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,18 +1,18 @@
from sqlalchemy import select, and_
from models import Deal, Pallet, Box
from models import Card, Pallet, Box
from models.shipping import ShippingProduct
from schemas.shipping import *
from services.base import BaseService
class ShippingService(BaseService):
async def create_pallet(self, deal_id: int) -> CreatePalletResponse:
deal = await self.session.get(Deal, deal_id)
async def create_pallet(self, card_id: int) -> CreatePalletResponse:
deal = await self.session.get(Card, card_id)
if not deal:
return CreatePalletResponse(ok=False, message="Сделка не найдена")
pallet = Pallet(deal_id=deal_id)
pallet = Pallet(card_id=card_id)
self.session.add(pallet)
await self.session.commit()
return CreatePalletResponse(ok=True, message="Паллет успешно создан")
@@ -36,19 +36,19 @@ class ShippingService(BaseService):
await self.session.commit()
return True, "Короб обновлен"
async def _create_box(self, data: CreateBoxInDealSchema | CreateBoxInPalletSchema):
async def _create_box(self, data: CreateBoxInCardSchema | CreateBoxInPalletSchema):
box = Box(**data.model_dump())
self.session.add(box)
await self.session.commit()
async def _create_box_in_deal(self, data: CreateBoxInDealSchema) -> tuple[bool, str]:
deal = await self.session.get(Deal, data.deal_id)
if not deal:
return False, f"Сделка с ID:{data.deal_id} не найдена"
async def _create_box_in_card(self, data: CreateBoxInCardSchema) -> tuple[bool, str]:
card = await self.session.get(Card, data.card_id)
if not card:
return False, f"Сделка с ID:{data.card_id} не найдена"
await self._create_box(data)
return True, f"Короб для сделки ID:{data.deal_id} добавлен"
return True, f"Короб для сделки ID:{data.card_id} добавлен"
async def _create_box_in_pallet(self, data: CreateBoxInPalletSchema) -> tuple[bool, str]:
pallet = await self.session.get(Pallet, data.pallet_id)
@@ -66,7 +66,7 @@ class ShippingService(BaseService):
elif "pallet_id" in data_keys:
ok, message = await self._create_box_in_pallet(CreateBoxInPalletSchema.model_validate(request.data))
else:
ok, message = await self._create_box_in_deal(CreateBoxInDealSchema.model_validate(request.data))
ok, message = await self._create_box_in_card(CreateBoxInCardSchema.model_validate(request.data))
return UpdateBoxResponse(ok=ok, message=message)