3
from typing import Any, Optional
5
from starlette.requests import Request
7
from app.inventory.order.models.order_models import Order
8
from app.inventory.order.schemas.order_schemas import OrderCreateScheme, OrderUpdateScheme, OrderFilter
9
from core.permissions import permit
10
from core.service.base import BaseService, UpdateSchemaType, ModelType, FilterSchemaType, CreateSchemaType
13
class OrderService(BaseService[Order, OrderCreateScheme, OrderUpdateScheme, OrderFilter]):
14
def __init__(self, request: Request):
15
super(OrderService, self).__init__(request, Order, OrderCreateScheme, OrderUpdateScheme)
18
async def update(self, id: Any, obj: UpdateSchemaType) -> Optional[ModelType]:
19
return await super(OrderService, self).update(id, obj)
22
async def list(self, _filter: FilterSchemaType, size: int):
23
return await super(OrderService, self).list(_filter, size)
25
@permit('order_create')
26
async def create(self, obj: CreateSchemaType) -> ModelType:
28
Метод создания ордера, в нем особой проверки не нужно, тк в теории ордер может быть создан как угодно
30
obj.number = datetime.datetime.now(datetime.UTC).strftime('%y%m%d%H%m%S')
31
obj.created_by = self.user.user_id
32
obj.edited_by = self.user.user_id
33
return await super(OrderService, self).create(obj)
35
@permit('order_delete')
36
async def delete(self, id: Any) -> None:
37
return await super(OrderService, self).delete(id)
39
@permit('order_move_counstructor')
40
async def move_counstructor(self, order_id: uuid.UUID, moves: list) -> None:
41
return await super(OrderService, self).delete(id)