diff --git a/models/module.py b/models/module.py index 8707d46..9850e18 100644 --- a/models/module.py +++ b/models/module.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Optional from sqlalchemy import Table, Column, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship @@ -23,6 +23,7 @@ class Module(BaseModel): id: Mapped[int] = mapped_column(primary_key=True) key: Mapped[str] = mapped_column(unique=True, nullable=False) label: Mapped[str] = mapped_column(nullable=False) + icon_name: Mapped[Optional[str]] = mapped_column(unique=True, nullable=False) is_deleted: Mapped[bool] = mapped_column(default=False) projects: Mapped[list['Project']] = relationship( diff --git a/models/project.py b/models/project.py index af1cd00..9f3a303 100644 --- a/models/project.py +++ b/models/project.py @@ -39,5 +39,6 @@ class Project(BaseModel): secondary='project_module', back_populates='projects', lazy='selectin', + order_by='asc(Module.id)', ) diff --git a/routers/card.py b/routers/card.py index 0236d9d..6c6a016 100644 --- a/routers/card.py +++ b/routers/card.py @@ -135,7 +135,7 @@ async def get_card_by_id( @card_router.post( '/update-general-info', response_model=CardUpdateGeneralInfoResponse, - operation_id='updateCardGeneralInfo', + operation_id='update_card_general_info', dependencies=[Depends(authorized_user)] ) async def update_general_info( @@ -146,6 +146,44 @@ async def update_general_info( return await CardsService(session).update_general_info(request, user) +@card_router.post( + '/update-products-and-services-general-info', + response_model=ProductsAndServicesGeneralInfoResponse, + operation_id='update_products_and_services_general_info', + dependencies=[Depends(authorized_user)] +) +async def update_products_and_services_general_info( + request: ProductsAndServicesGeneralInfoRequest, + session: Annotated[AsyncSession, Depends(get_session)], +): + return await CardsService(session).update_products_and_services_general_info(request) + + +@card_router.post( + '/update-card-manager', + response_model=UpdateCardManagerResponse, + operation_id='update_card_manager', + dependencies=[Depends(authorized_user)] +) +async def update_card_manager( + request: UpdateCardManagerRequest, + session: Annotated[AsyncSession, Depends(get_session)], +): + return await CardsService(session).update_card_manager(request) + + +@card_router.post( + '/update-card-client', + response_model=UpdateCardClientResponse, + operation_id='update_card_client', + dependencies=[Depends(authorized_user)] +) +async def update_card_client( + request: UpdateCardClientRequest, + session: Annotated[AsyncSession, Depends(get_session)], +): + return await CardsService(session).update_card_client(request) + @card_router.post( '/add-kit', response_model=CardAddKitResponse, diff --git a/routers/project.py b/routers/project.py index 8d64726..776575f 100644 --- a/routers/project.py +++ b/routers/project.py @@ -11,7 +11,6 @@ from services.project import ProjectService project_router = APIRouter( prefix="/project", tags=["project"], - dependencies=[Depends(guest_user)] ) diff --git a/schemas/card.py b/schemas/card.py index 12e96c6..5f540f4 100644 --- a/schemas/card.py +++ b/schemas/card.py @@ -111,14 +111,17 @@ class CardGeneralInfoSchema(BaseSchemaWithAttributes): is_deleted: bool is_completed: bool comment: str - shipping_warehouse: Optional[str] = None manager: Optional[UserSchema] = None board_id: int status_id: int - is_services_profit_accounted: bool client_id: Optional[int] +class ProductsAndServicesGeneralInfoSchema(BaseSchema): + shipping_warehouse: Optional[str] = None + is_services_profit_accounted: bool + + class OptionalShippingWarehouseSchema(BaseShippingWarehouseSchema): id: Optional[int] = None @@ -228,6 +231,21 @@ class CardUpdateGeneralInfoRequest(BaseSchema): data: CardGeneralInfoSchema +class ProductsAndServicesGeneralInfoRequest(BaseSchema): + card_id: int + data: ProductsAndServicesGeneralInfoSchema + + +class UpdateCardManagerRequest(BaseSchema): + card_id: int + manager_id: Optional[int] + + +class UpdateCardClientRequest(BaseSchema): + card_id: int + client_id: int + + class CardSummaryReorderRequest(BaseSchema): card_id: int status_id: int @@ -360,6 +378,18 @@ class CardUpdateGeneralInfoResponse(OkMessageSchema): pass +class ProductsAndServicesGeneralInfoResponse(OkMessageSchema): + pass + + +class UpdateCardManagerResponse(OkMessageSchema): + pass + + +class UpdateCardClientResponse(OkMessageSchema): + pass + + class CardSummaryReorderResponse(OkMessageSchema): pass @@ -416,5 +446,4 @@ class ParseCardsExcelResponse(BaseSchema): class CreateCardsFromExcelResponse(OkMessageSchema): pass - # endregion Responses diff --git a/schemas/project.py b/schemas/project.py index a8344ce..318e1d2 100644 --- a/schemas/project.py +++ b/schemas/project.py @@ -1,3 +1,5 @@ +from typing import Optional + from schemas.attribute import AttributeSchema from schemas.base import BaseSchema, OkMessageSchema @@ -17,6 +19,7 @@ class ModuleSchema(BaseSchema): id: int key: str label: str + icon_name: Optional[str] = None is_deleted: bool diff --git a/services/barcode.py b/services/barcode.py index 82a913d..9b3bc2f 100644 --- a/services/barcode.py +++ b/services/barcode.py @@ -135,7 +135,7 @@ class BarcodeService(BaseService): "barcode_image_url": uploader.get_abs_path(card_product.product.barcode_image.filename), "num_duplicates": card_product.quantity }) - else: + elif len(card_product.product.barcodes) > 0: product_request = GetProductBarcodeRequest( product_id=card_product.product_id, barcode="", @@ -148,6 +148,8 @@ class BarcodeService(BaseService): "template": barcode_template, "num_duplicates": card_product.quantity }) + else: + print("jaja") default_generator = DefaultBarcodeGenerator() filename = f'{card.id}_deal_barcodes.pdf' diff --git a/services/card.py b/services/card.py index 289469b..84a7650 100644 --- a/services/card.py +++ b/services/card.py @@ -368,14 +368,6 @@ class CardsService(BaseService): card.board_id = request.data.board_id await self.change_status(card, request.data.status_id, user) - # Updating shipping warehouse - shipping_warehouse_service = ShippingWarehouseService(self.session) - shipping_warehouse = await shipping_warehouse_service.get_by_name(request.data.shipping_warehouse) - if not shipping_warehouse and request.data.shipping_warehouse: - shipping_warehouse = await shipping_warehouse_service.create_by_name(request.data.shipping_warehouse) - - card.shipping_warehouse = shipping_warehouse - # Updating manager if request.data.manager: card.manager_id = request.data.manager.id @@ -391,6 +383,47 @@ class CardsService(BaseService): await self.session.rollback() return CardUpdateGeneralInfoResponse(ok=False, message=str(e)) + async def update_products_and_services_general_info(self, request: ProductsAndServicesGeneralInfoRequest) -> ( + ProductsAndServicesGeneralInfoResponse + ): + card: Optional[Card] = await self.session.get(Card, request.card_id) + if not card: + raise HTTPException(status_code=404, detail='Карточка не найдена') + + # Updating shipping warehouse + shipping_warehouse_service = ShippingWarehouseService(self.session) + shipping_warehouse = await shipping_warehouse_service.get_by_name(request.data.shipping_warehouse) + if not shipping_warehouse and request.data.shipping_warehouse: + shipping_warehouse = await shipping_warehouse_service.create_by_name(request.data.shipping_warehouse) + + if card.group: + for card in card.group.cards: + card.is_services_profit_accounted = request.data.is_services_profit_accounted + else: + card.is_services_profit_accounted = request.data.is_services_profit_accounted + + card.shipping_warehouse = shipping_warehouse + await self.session.commit() + return ProductsAndServicesGeneralInfoResponse(ok=True, message='Данные карточки успешно обновлены') + + async def update_card_manager(self, request: UpdateCardManagerRequest) -> UpdateCardManagerResponse: + card: Optional[Card] = await self.session.get(Card, request.card_id) + if not card: + raise HTTPException(status_code=404, detail='Карточка не найдена') + + card.manager_id = request.manager_id + await self.session.commit() + return UpdateCardManagerResponse(ok=True, message='Данные карточки успешно обновлены') + + async def update_card_client(self, request: UpdateCardClientRequest) -> UpdateCardClientResponse: + card: Optional[Card] = await self.session.get(Card, request.card_id) + if not card: + raise HTTPException(status_code=404, detail='Карточка не найдена') + + card.client_id = request.client_id + await self.session.commit() + return UpdateCardClientResponse(ok=True, message='Данные карточки успешно обновлены') + async def reorder(self, request: CardSummaryReorderRequest, user: User) -> CardSummaryResponse: card: Card = await self.session.scalar(select(Card).where(Card.id == request.card_id)) if request.index == 1: