feat: split bills for one deal

This commit is contained in:
2025-05-09 13:32:30 +04:00
parent 42ce73dd6a
commit be13c77164
12 changed files with 154 additions and 90 deletions

View File

@@ -4,7 +4,7 @@ import lexorank
import math
from fastapi import HTTPException
from sqlalchemy import select, func, update, delete, insert, and_, Select
from sqlalchemy.orm import joinedload, selectinload
from sqlalchemy.orm import joinedload, selectinload, noload
from starlette import status
from card_attributes import CardAttributesCommandHandler
@@ -252,9 +252,10 @@ class CardsService(BaseService):
selectinload(Card.status_history),
joinedload(Card.client),
joinedload(Card.shipping_warehouse),
joinedload(Card.bill_request),
selectinload(Card.bill_requests),
joinedload(Card.status),
joinedload(Card.board),
joinedload(Card.group).selectinload(CardGroup.bill_requests)
)
.outerjoin(
price_subquery, Card.id == price_subquery.c.card_id,
@@ -299,7 +300,7 @@ class CardsService(BaseService):
shipment_warehouse_id=card.shipping_warehouse_id,
shipment_warehouse_name=shipment_warehouse_name,
total_products=products_count,
bill_request=card.bill_request,
bill_requests=card.bill_requests,
tags=card.tags,
attributes=attributes,
)
@@ -335,7 +336,7 @@ class CardsService(BaseService):
.joinedload(CardStatusHistory.user),
selectinload(Card.status_history)
.noload(CardStatusHistory.card),
selectinload(Card.bill_requests),
)
)
)
@@ -1229,14 +1230,16 @@ class CardsService(BaseService):
async def _recalculate_price_group(self, group: CardGroup):
cards = await self.session.scalars(
select(Card)
.join(card_relations, Card.id == card_relations.c.card_id)
.options(
selectinload(Card.services)
.joinedload(CardService.service),
selectinload(Card.products)
.selectinload(CardProduct.services)
.joinedload(CardProductService.service),
noload(Card.group)
)
.where(Card.group == group)
.where(card_relations.c.group_id == group.id)
)
cards = list(cards.all())
services_quantity = await self.get_quantity_dict(cards)