1
from datetime import datetime
2
from typing import Optional, List
4
from fastapi_filter.contrib.sqlalchemy import Filter
5
from pydantic import BaseModel, Field, computed_field
6
from pydantic.types import UUID4
8
from app.inventory.location.enums import LocationClass
9
from app.inventory.quant.models import Quant
10
from core.schemas import BaseFilter
11
from core.schemas.basic_schemes import BasicModel
12
from core.schemas.list_schema import GenericListSchema
13
from core.schemas.timestamps import TimeStampScheme
16
class QuantBaseScheme(BasicModel):
17
vars: Optional[dict] = None
18
product_id: UUID4 = Field(title='Product ID', model='product')
19
store_id: UUID4 = Field(title='Store ID', model='store')
20
location_class: LocationClass = Field(title='Location Class')
21
location_type_id: UUID4 = Field(title='Location Type ID', model='location_type')
22
location_id: Optional[UUID4] = Field(title='Location ID', model='location')
23
lot_id: Optional[UUID4] = Field(default=None, title='Lot ID', model='lot')
24
partner_id: Optional[UUID4] = Field(default=None, title='Partner ID', model='partner')
25
quantity: float = Field(title='Quantity')
26
reserved_quantity: Optional[float] = Field(default=0.0, title='Reserved Quantity')
27
incoming_quantity: Optional[float] = Field(default=0.0, title='Incoming Quantity')
28
expiration_datetime: Optional[datetime] = Field(default=None, title='Expiration Datetime')
29
uom_id: UUID4 = Field(title='UOM ID', model='uom')
30
move_ids: Optional[list[UUID4]] = Field(default=[], title='Move IDs')
34
from_attributes = True
36
service = 'app.inventory.quant.services.QuantService'
38
class QuantUpdateScheme(QuantBaseScheme):
39
store_id: Optional[UUID4] = Field(default=None, title='Store ID', model='store')
40
quantity: Optional[float] = Field(default=None, title='Quantity')
41
reserved_quantity: Optional[float] = Field(default=None, title='Reserved Quantity')
42
uom_id: Optional[UUID4] = Field(default=None, title='UOM ID', model='uom')
45
class QuantCreateScheme(QuantBaseScheme):
49
class QuantScheme(QuantCreateScheme, TimeStampScheme):
50
company_id: UUID4 = Field(title='Company ID', model='company')
56
def title(self) -> str:
57
return f'Q-{self.quantity} | R-{self.reserved_quantity} | I-{self.incoming_quantity}'
60
from_attributes = True
63
class QuantFilter(BaseFilter):
65
populate_by_name = True
67
class Constants(Filter.Constants):
69
ordering_field_name = "order_by"
70
search_field_name = "search"
71
search_model_fields = ["company_id", "product_id", "lot_id"]
74
class QuantListSchema(GenericListSchema):
75
data: Optional[List[QuantScheme]]