38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
from datetime import datetime
|
|
from enum import Enum as PyEnum
|
|
|
|
from sqlalchemy import Column, DateTime, Enum, Float, ForeignKey, Integer, String
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.models.base import Base
|
|
|
|
|
|
class TransactionType(str, PyEnum):
|
|
"""
|
|
Enum for transaction types.
|
|
"""
|
|
PURCHASE = "purchase"
|
|
SALE = "sale"
|
|
ADJUSTMENT = "adjustment"
|
|
RETURN = "return"
|
|
|
|
|
|
class Transaction(Base):
|
|
"""
|
|
Transaction model for tracking inventory changes.
|
|
"""
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
transaction_type = Column(Enum(TransactionType), nullable=False)
|
|
quantity = Column(Integer, nullable=False)
|
|
unit_price = Column(Float, nullable=True)
|
|
reference_number = Column(String, nullable=True)
|
|
notes = Column(String, nullable=True)
|
|
transaction_date = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
|
|
# Foreign key to Item
|
|
item_id = Column(Integer, ForeignKey("item.id"), nullable=False)
|
|
item = relationship("Item", backref="transactions")
|
|
|
|
# Foreign key to User (who recorded the transaction)
|
|
recorded_by_id = Column(Integer, ForeignKey("user.id"), nullable=True)
|
|
recorded_by = relationship("User", backref="transactions") |