feat: disabling accounting for deals and groups
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
from audioop import ratecv
|
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ class Deal(BaseModel):
|
|||||||
is_deleted = Column(Boolean, nullable=False, server_default='0', default=False, comment='Удалена')
|
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_completed = Column(Boolean, nullable=False, server_default='0', default=False, comment='Завершена')
|
||||||
is_locked: Mapped[bool] = mapped_column(default=False, server_default='0')
|
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_id: Mapped[int] = mapped_column(ForeignKey('shipping_warehouses.id'), nullable=True)
|
||||||
shipping_warehouse: Mapped["ShippingWarehouse"] = relationship()
|
shipping_warehouse: Mapped["ShippingWarehouse"] = relationship()
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ class DealSchema(BaseSchema):
|
|||||||
is_deleted: bool
|
is_deleted: bool
|
||||||
is_completed: bool
|
is_completed: bool
|
||||||
is_locked: bool
|
is_locked: bool
|
||||||
|
is_accounted: bool
|
||||||
client: ClientSchema
|
client: ClientSchema
|
||||||
comment: str
|
comment: str
|
||||||
shipping_warehouse: Optional[Union[ShippingWarehouseSchema, str]] = None
|
shipping_warehouse: Optional[Union[ShippingWarehouseSchema, str]] = None
|
||||||
@@ -120,6 +121,7 @@ class DealGeneralInfoSchema(BaseSchema):
|
|||||||
name: str
|
name: str
|
||||||
is_deleted: bool
|
is_deleted: bool
|
||||||
is_completed: bool
|
is_completed: bool
|
||||||
|
is_accounted: bool
|
||||||
comment: str
|
comment: str
|
||||||
shipping_warehouse: Optional[str] = None
|
shipping_warehouse: Optional[str] = None
|
||||||
delivery_date: Optional[datetime.datetime] = None
|
delivery_date: Optional[datetime.datetime] = None
|
||||||
|
|||||||
@@ -352,7 +352,14 @@ class DealService(BaseService):
|
|||||||
|
|
||||||
async def update_general_info(self, request: DealUpdateGeneralInfoRequest) -> DealUpdateGeneralInfoResponse:
|
async def update_general_info(self, request: DealUpdateGeneralInfoRequest) -> DealUpdateGeneralInfoResponse:
|
||||||
try:
|
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:
|
if not deal:
|
||||||
raise HTTPException(status_code=404, detail="Сделка не найдена")
|
raise HTTPException(status_code=404, detail="Сделка не найдена")
|
||||||
deal.name = request.data.name
|
deal.name = request.data.name
|
||||||
@@ -362,6 +369,12 @@ class DealService(BaseService):
|
|||||||
deal.delivery_date = request.data.delivery_date
|
deal.delivery_date = request.data.delivery_date
|
||||||
deal.receiving_slot_date = request.data.receiving_slot_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
|
# Updating shipping warehouse
|
||||||
shipping_warehouse_service = ShippingWarehouseService(self.session)
|
shipping_warehouse_service = ShippingWarehouseService(self.session)
|
||||||
shipping_warehouse = await shipping_warehouse_service.get_by_name(request.data.shipping_warehouse)
|
shipping_warehouse = await shipping_warehouse_service.get_by_name(request.data.shipping_warehouse)
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class ProfitStatisticsService(BaseService):
|
|||||||
.join(DealService, Deal.id == DealService.deal_id)
|
.join(DealService, Deal.id == DealService.deal_id)
|
||||||
.join(Service, DealService.service_id == Service.id)
|
.join(Service, DealService.service_id == Service.id)
|
||||||
.join(sub_filtered_status_history, Deal.id == sub_filtered_status_history.c.deal_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")
|
.group_by(Deal.id, "date")
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ class ProfitStatisticsService(BaseService):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.join(Service, DealProductService.service_id == Service.id)
|
.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)
|
.group_by(Deal.id)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user