lavkach3

Форк
0
75 строк · 2.8 Кб
1
from datetime import datetime
2
from typing import Optional, List
3

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

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
14

15

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')
31

32
    class Config:
33
        extra = 'allow'
34
        from_attributes = True
35
        orm_model = Quant
36
        service = 'app.inventory.quant.services.QuantService'
37

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')
43

44

45
class QuantCreateScheme(QuantBaseScheme):
46
    ...
47

48

49
class QuantScheme(QuantCreateScheme, TimeStampScheme):
50
    company_id: UUID4 = Field(title='Company ID', model='company')
51
    lsn: int
52
    id: UUID4
53

54
    @computed_field
55
    @property
56
    def title(self) -> str:
57
        return f'Q-{self.quantity} | R-{self.reserved_quantity} | I-{self.incoming_quantity}'
58

59
    class Config:
60
        from_attributes = True
61

62

63
class QuantFilter(BaseFilter):
64
    class Config:
65
        populate_by_name = True
66

67
    class Constants(Filter.Constants):
68
        model = Quant
69
        ordering_field_name = "order_by"
70
        search_field_name = "search"
71
        search_model_fields = ["company_id", "product_id", "lot_id"]
72

73

74
class QuantListSchema(GenericListSchema):
75
    data: Optional[List[QuantScheme]]
76

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

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

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

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