lavkach3

Форк
0
89 строк · 4.0 Кб
1
from __future__ import annotations
2

3
from typing import Optional, List, TYPE_CHECKING
4

5
from fastapi_filter.contrib.sqlalchemy import Filter
6
from pydantic import Field, computed_field
7
from pydantic.types import UUID4
8

9
from app.inventory.location.enums import LocationClass
10
from app.inventory.order.enums.order_enum import MoveStatus, MoveType, move_color_map
11
from app.inventory.order.models import Move
12
from app.inventory.order.schemas.suggest_schemas import SuggestScheme, SuggestCreateScheme, SuggestUpdateScheme
13
from core.frontend.enviroment import readonly_fields
14
from core.schemas import BaseFilter
15
from core.schemas.basic_schemes import ActionBaseSchame, BasicModel
16
from core.schemas.list_schema import GenericListSchema
17
from core.schemas.timestamps import TimeStampScheme
18

19

20
class MoveBaseScheme(BasicModel):
21
    type: MoveType = Field(title='Move Type', table=True, readonly=True)
22
    order_id: Optional[UUID4] = Field(default=None, title='Order ID', model='order')
23
    order_type_id: UUID4 = Field(title='Order type', model='order_type', table=True)
24
    store_id: UUID4 = Field(title='Store', table=True, form=True, model='store')
25
    partner_id: Optional[UUID4] = Field(default=None, title='Partner ID', model='partner')
26
    location_src_id: Optional[UUID4] = Field(default=None, title='Location src', model='location', table=True, filter={'location_class__not_in': LocationClass.PACKAGE.value})
27
    location_dest_id: Optional[UUID4] = Field(default=None, title='Location dest', model='location', table=True, filter={'location_class__not_in': LocationClass.PACKAGE.value})
28
    lot_id: Optional[UUID4] = Field(default=None, title='Lot', table=True, model='lot')
29
    location_id: Optional[UUID4] = Field(default=None, title='Package', table=True, model='location', filter={'location_class__in': LocationClass.PACKAGE.value})
30
    # ONE OF Возможно либо location_id либо product_id
31
    product_id: Optional[UUID4] = Field(default=None, title='Product', table=True, model='product')
32
    quantity: float = Field(title='Quantity', table=True)
33
    uom_id: Optional[UUID4] = Field(default=None, title='Uom', table=True, model='uom')
34
    quant_src_id: Optional[UUID4] = Field(default=None, title='Quant source', table=True, model='quant')
35
    quant_dest_id: Optional[UUID4] = Field(default=None, title='Quant dest', table=True, model='quant')
36
    status: MoveStatus = Field(title='Status', table=True, readonly=True, color_map=move_color_map)
37

38
    class Config:
39
        orm_model = Move
40

41
class MoveUpdateScheme(MoveBaseScheme):
42
    suggest_list_rel: Optional[list[SuggestUpdateScheme]] = Field(default=[], title='Suggests', form=True)
43
    order_id: Optional[UUID4] = Field(default=None, title='Order ID', model='order',readonly=True)
44
    ...
45

46

47
class MoveCreateScheme(MoveBaseScheme):
48
    suggest_list_rel: Optional[list[SuggestCreateScheme]] = Field(default=[], title='Suggests', form=True)
49
    ...
50

51

52
class MoveScheme(MoveCreateScheme, TimeStampScheme):
53
    company_id: UUID4 = Field(model='company', title='Company')
54
    lsn: int
55
    id: UUID4
56
    move_id: Optional[UUID4] = Field(default=None, model='move', title='Parent Move')
57
    suggest_list_rel: Optional[list[SuggestScheme]] = Field(default=[], title='Suggests', form=True)
58

59
    @computed_field
60
    @property
61
    def title(self) -> str:
62
        return f'[{self.type.name}] - {self.quantity} - {self.status.name}'
63

64

65
class MoveFilter(BaseFilter):
66
    store_id__in: Optional[List[UUID4]] = Field(default=None, title='Store', model='store')
67
    order_id__in: Optional[List[UUID4]] = Field(default=None, title='Order', model='order')
68

69
    class Config:
70
        populate_by_name = True
71

72
    class Constants(Filter.Constants):
73
        model = Move
74
        ordering_field_name = "order_by"
75
        search_field_name = "search"
76
        search_model_fields = ["order_id", "product_id"]
77

78

79
class MoveListSchema(GenericListSchema):
80
    data: Optional[List[MoveScheme]]
81

82
class MoveConfirmScheme(ActionBaseSchame):
83

84
    class Config:
85
        extra = 'allow'
86

87
class GetMovesByBarcode(BasicModel):
88
    barcode: str
89
    order_id: Optional[UUID4]

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.