1
from __future__ import annotations
3
from typing import Optional, List, TYPE_CHECKING
5
from fastapi_filter.contrib.sqlalchemy import Filter
6
from pydantic import Field, computed_field
7
from pydantic.types import UUID4
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
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)
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)
47
class MoveCreateScheme(MoveBaseScheme):
48
suggest_list_rel: Optional[list[SuggestCreateScheme]] = Field(default=[], title='Suggests', form=True)
52
class MoveScheme(MoveCreateScheme, TimeStampScheme):
53
company_id: UUID4 = Field(model='company', title='Company')
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)
61
def title(self) -> str:
62
return f'[{self.type.name}] - {self.quantity} - {self.status.name}'
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')
70
populate_by_name = True
72
class Constants(Filter.Constants):
74
ordering_field_name = "order_by"
75
search_field_name = "search"
76
search_model_fields = ["order_id", "product_id"]
79
class MoveListSchema(GenericListSchema):
80
data: Optional[List[MoveScheme]]
82
class MoveConfirmScheme(ActionBaseSchame):
87
class GetMovesByBarcode(BasicModel):
89
order_id: Optional[UUID4]