forked from hesabix/arc
Keep per-combination warehouse balances off by default, then allocate invoice and warehouse lines to those combinations when a product uses inventory attributes. Co-authored-by: Cursor <cursoragent@cursor.com>
33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
|
|
from sqlalchemy import BigInteger, DateTime, ForeignKey, Integer, Numeric
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from adapters.db.session import Base
|
|
|
|
|
|
class InventoryVariantBalance(Base):
|
|
"""Projection مانده Variant؛ قابل بازسازی از حوالههای posted است، دفتر حسابرسی نیست."""
|
|
|
|
__tablename__ = "inventory_variant_balances"
|
|
|
|
business_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("businesses.id", ondelete="CASCADE"), primary_key=True
|
|
)
|
|
warehouse_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("warehouses.id", ondelete="CASCADE"), primary_key=True
|
|
)
|
|
product_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("products.id", ondelete="CASCADE"), primary_key=True
|
|
)
|
|
variant_id: Mapped[int] = mapped_column(
|
|
BigInteger, ForeignKey("product_variants.id", ondelete="CASCADE"), primary_key=True
|
|
)
|
|
quantity: Mapped[Decimal] = mapped_column(Numeric(18, 6), nullable=False, default=0)
|
|
version: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False
|
|
)
|