From e65ca07accdb7fd46f900f8359371779788289da Mon Sep 17 00:00:00 2001 From: AlexSserb Date: Fri, 3 Jan 2025 20:46:48 +0400 Subject: [PATCH] feat: disabling accounting for deals and groups --- marketplaces/factory.py | 1 - models/deal.py | 1 + schemas/deal.py | 2 ++ services/deal.py | 15 ++++++++++++++- services/statistics/profit_statistics.py | 4 ++-- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/marketplaces/factory.py b/marketplaces/factory.py index 270dc28..a978298 100644 --- a/marketplaces/factory.py +++ b/marketplaces/factory.py @@ -1,4 +1,3 @@ -from audioop import ratecv from typing import Union from sqlalchemy.ext.asyncio import AsyncSession diff --git a/models/deal.py b/models/deal.py index 1d94787..572e809 100644 --- a/models/deal.py +++ b/models/deal.py @@ -63,6 +63,7 @@ class Deal(BaseModel): is_deleted = Column(Boolean, nullable=False, server_default='0', default=False, comment='Удалена') is_completed = Column(Boolean, nullable=False, server_default='0', default=False, comment='Завершена') is_locked: Mapped[bool] = mapped_column(default=False, server_default='0') + is_accounted: Mapped[bool] = mapped_column(default=True, server_default='1') shipping_warehouse_id: Mapped[int] = mapped_column(ForeignKey('shipping_warehouses.id'), nullable=True) shipping_warehouse: Mapped["ShippingWarehouse"] = relationship() diff --git a/schemas/deal.py b/schemas/deal.py index 91459a4..30736e4 100644 --- a/schemas/deal.py +++ b/schemas/deal.py @@ -101,6 +101,7 @@ class DealSchema(BaseSchema): is_deleted: bool is_completed: bool is_locked: bool + is_accounted: bool client: ClientSchema comment: str shipping_warehouse: Optional[Union[ShippingWarehouseSchema, str]] = None @@ -120,6 +121,7 @@ class DealGeneralInfoSchema(BaseSchema): name: str is_deleted: bool is_completed: bool + is_accounted: bool comment: str shipping_warehouse: Optional[str] = None delivery_date: Optional[datetime.datetime] = None diff --git a/services/deal.py b/services/deal.py index 28a7a4e..1cf7197 100644 --- a/services/deal.py +++ b/services/deal.py @@ -352,7 +352,14 @@ class DealService(BaseService): async def update_general_info(self, request: DealUpdateGeneralInfoRequest) -> DealUpdateGeneralInfoResponse: try: - deal: Deal = await self.session.scalar(select(Deal).where(Deal.id == request.deal_id)) + deal: Deal = await self.session.scalar( + select(Deal) + .options( + selectinload(Deal.group) + .selectinload(DealGroup.deals) + ) + .where(Deal.id == request.deal_id) + ) if not deal: raise HTTPException(status_code=404, detail="Сделка не найдена") deal.name = request.data.name @@ -362,6 +369,12 @@ class DealService(BaseService): deal.delivery_date = request.data.delivery_date deal.receiving_slot_date = request.data.receiving_slot_date + if deal.group: + for deal in deal.group.deals: + deal.is_accounted = request.data.is_accounted + else: + deal.is_accounted = request.data.is_accounted + # Updating shipping warehouse shipping_warehouse_service = ShippingWarehouseService(self.session) shipping_warehouse = await shipping_warehouse_service.get_by_name(request.data.shipping_warehouse) diff --git a/services/statistics/profit_statistics.py b/services/statistics/profit_statistics.py index 4ded474..2a83f2e 100644 --- a/services/statistics/profit_statistics.py +++ b/services/statistics/profit_statistics.py @@ -112,7 +112,7 @@ class ProfitStatisticsService(BaseService): .join(DealService, Deal.id == DealService.deal_id) .join(Service, DealService.service_id == Service.id) .join(sub_filtered_status_history, Deal.id == sub_filtered_status_history.c.deal_id) - .where(Deal.is_deleted == False) + .where(and_(Deal.is_deleted == False, Deal.is_accounted == True)) .group_by(Deal.id, "date") ) @@ -154,7 +154,7 @@ class ProfitStatisticsService(BaseService): ) ) .join(Service, DealProductService.service_id == Service.id) - .where(Deal.is_deleted == False) + .where(and_(Deal.is_deleted == False, Deal.is_accounted == True)) .group_by(Deal.id) )