3
from typing import Optional
5
from sqlalchemy import Sequence, Uuid, ForeignKey, DateTime, UniqueConstraint
6
from sqlalchemy.orm import relationship, mapped_column, Mapped
9
from app.inventory.order.enums.order_enum import OrderStatus
10
from app.inventory.quant.models import Lot
11
from core.db import Base
12
from core.db.mixins import AllMixin, CreatedEdited
13
from core.db.types import ids
16
class Document(Base, AllMixin, CreatedEdited):
18
Документ, который является основанием для изменения запаса
20
__tablename__ = "document"
22
UniqueConstraint('external_number', 'company_id', name='_document_companyid_external_number_uc'),
24
lsn_seq = Sequence(f'document_lsn_seq')
25
number: Mapped[str] = mapped_column(index=True)
26
external_number: Mapped[Optional[str]]
27
store_id: Mapped[uuid.UUID] = mapped_column(Uuid, index=True)
28
partner_id: Mapped[Optional[uuid.UUID]] = mapped_column(Uuid, index=True)
29
lot_id: Mapped[Optional['Lot']] = mapped_column(ForeignKey("lot.id", ondelete="SET NULL"))
30
origin_type: Mapped[Optional[str]] = mapped_column(index=True)
31
origin_number: Mapped[Optional[str]] = mapped_column(index=True)
32
planned_datetime: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime(timezone=True))
33
actual_datetime: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime(timezone=True))
34
expiration_datetime: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime(timezone=True))
35
user_ids: Mapped[Optional[ids]] = mapped_column(index=True)
36
description: Mapped[Optional[str]]
37
status: Mapped['OrderStatus'] = mapped_column(default=OrderStatus.DRAFT)
38
move_list_rel: Mapped[Optional[list["Move"]]] = relationship(back_populates="order_rel", lazy="selectin")
40
def __init__(self, **kwargs):
42
Разрешает экстра поля, но удаляет, если их нет в табличке
44
allowed_args = self.__mapper__.class_manager
45
kwargs = {k: v for k, v in kwargs.items() if k in allowed_args}
46
super().__init__(**kwargs)