feat: shipping warehouse and cost
This commit is contained in:
@@ -13,6 +13,7 @@ from schemas.client import ClientDetailsSchema
|
||||
from schemas.deal import *
|
||||
from services.base import BaseService
|
||||
from services.client import ClientService
|
||||
from services.shipping_warehouse import ShippingWarehouseService
|
||||
|
||||
|
||||
class DealService(BaseService):
|
||||
@@ -90,6 +91,10 @@ class DealService(BaseService):
|
||||
request.client_name,
|
||||
ClientDetailsSchema()
|
||||
)
|
||||
shipping_warehouse_service = ShippingWarehouseService(self.session)
|
||||
shipping_warehouse = await shipping_warehouse_service.get_by_name(name=request.shipping_warehouse)
|
||||
if not shipping_warehouse:
|
||||
shipping_warehouse = await shipping_warehouse_service.create_by_name(name=request.shipping_warehouse)
|
||||
|
||||
rank = await self._get_rank_for_deal(DealStatus.CREATED)
|
||||
deal = Deal(
|
||||
@@ -97,7 +102,8 @@ class DealService(BaseService):
|
||||
created_at=datetime.datetime.now(),
|
||||
client_id=client.id,
|
||||
current_status=DealStatus.CREATED,
|
||||
lexorank=rank
|
||||
lexorank=rank,
|
||||
shipping_warehouse_id=shipping_warehouse.id
|
||||
)
|
||||
self.session.add(deal)
|
||||
await self.session.flush()
|
||||
@@ -167,7 +173,8 @@ class DealService(BaseService):
|
||||
price_subquery, Deal.id == price_subquery.c.deal_id)
|
||||
.where(
|
||||
Deal.is_deleted == False,
|
||||
Deal.is_completed == False
|
||||
Deal.is_completed == False,
|
||||
Deal.current_status != DealStatus.COMPLETED
|
||||
)
|
||||
)
|
||||
deals_query = await self.session.execute(q)
|
||||
@@ -203,7 +210,9 @@ class DealService(BaseService):
|
||||
deal = await self.session.scalar(
|
||||
select(Deal)
|
||||
.options(
|
||||
joinedload(Deal.client).joinedload(Client.details),
|
||||
joinedload(Deal.shipping_warehouse),
|
||||
joinedload(Deal.client)
|
||||
.joinedload(Client.details),
|
||||
selectinload(Deal.services)
|
||||
.joinedload(models.secondary.DealService.service)
|
||||
.joinedload(Service.category),
|
||||
@@ -220,6 +229,7 @@ class DealService(BaseService):
|
||||
.joinedload(DealStatusHistory.user),
|
||||
selectinload(Deal.status_history)
|
||||
.noload(DealStatusHistory.deal),
|
||||
|
||||
)
|
||||
.where(Deal.id == deal_id)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user