Add schema model for Purchase Orders

This commit is contained in:
Lance Edgar 2021-02-01 15:30:55 -06:00
parent ee9451588c
commit 1757d09781

View file

@ -1547,3 +1547,121 @@ class BatchItem(Base):
def __str__(self):
return self.upc or ""
class PurchaseOrder(Base):
"""
Represents a purchase order.
"""
__tablename__ = 'PurchaseOrder'
# TODO: would be simpler to declare these, but is it safe?
# __table_args__ = (
# sa.ForeignKeyConstraint(['vendorID'], ['vendors.vendorID']),
# sa.ForeignKeyConstraint(['storeID'], ['Stores.storeID']),
# )
orderID = sa.Column(sa.Integer(), nullable=False, primary_key=True, autoincrement=True)
id = orm.synonym('orderID')
vendor_id = sa.Column('vendorID', sa.Integer(), nullable=True)
vendor = orm.relationship(
Vendor,
primaryjoin=Vendor.id == vendor_id,
foreign_keys=[vendor_id])
store_id = sa.Column('storeID', sa.Integer(), nullable=True)
store = orm.relationship(
Store,
primaryjoin=Store.id == store_id,
foreign_keys=[store_id])
creation_date = sa.Column('creationDate', sa.DateTime(), nullable=True)
placed = sa.Column(sa.Boolean(), nullable=True, default=False)
placed_date = sa.Column('placedDate', sa.DateTime(), nullable=True)
user_id = sa.Column('userID', sa.Integer(), nullable=True)
vendor_order_id = sa.Column('vendorOrderID', sa.String(length=25), nullable=True)
vendor_invoice_id = sa.Column('vendorInvoiceID', sa.String(length=25), nullable=True)
standing_id = sa.Column('standingID', sa.Integer(), nullable=True)
inventory_ignore = sa.Column('inventoryIgnore', sa.Boolean(), nullable=True, default=False)
transfer_id = sa.Column('transferID', sa.Integer(), nullable=True)
notes = association_proxy('notes', 'notes')
def __str__(self):
return "#{} for {}".format(self.id, self.vendor or "??")
class PurchaseOrderItem(Base):
"""
Represents a line item in a purchase order.
"""
__tablename__ = 'PurchaseOrderItems'
__table_args__ = (
sa.ForeignKeyConstraint(['orderID'], ['PurchaseOrder.orderID']),
)
order_id = sa.Column('orderID', sa.Integer(), nullable=False,
primary_key=True, autoincrement=False)
order = orm.relationship(PurchaseOrder, backref=orm.backref('items'))
sku = sa.Column(sa.String(length=13), nullable=False,
primary_key=True)
quantity = sa.Column(sa.Numeric(precision=10, scale=2), nullable=True)
unit_cost = sa.Column('unitCost', sa.Numeric(precision=10, scale=4), nullable=True)
case_size = sa.Column('caseSize', sa.Float(), nullable=True)
received_date = sa.Column('receivedDate', sa.DateTime(), nullable=True)
received_quantity = sa.Column('receivedQty', sa.Float(), nullable=True)
received_total_cost = sa.Column('receivedTotalCost', sa.Numeric(precision=10, scale=4), nullable=True)
unit_size = sa.Column('unitSize', sa.String(length=25), nullable=True)
brand = sa.Column(sa.String(length=50), nullable=True)
description = sa.Column(sa.String(length=50), nullable=True)
internal_upc = sa.Column('internalUPC', sa.String(length=13), nullable=True)
sales_code = sa.Column('salesCode', sa.Integer(), nullable=True)
is_special_order = sa.Column('isSpecialOrder', sa.Boolean(), nullable=True,
default=False)
# TODO: this probably is FK to e.g. User.id ?
received_by = sa.Column('receivedBy', sa.Integer(), nullable=True,
default=0)
def __str__(self):
return self.description or ""
class PurchaseOrderNote(Base):
"""
Represents a note attached to a purchase order.
"""
__tablename__ = 'PurchaseOrderNotes'
__table_args__ = (
sa.ForeignKeyConstraint(['orderID'], ['PurchaseOrder.orderID']),
)
order_id = sa.Column('orderID', sa.Integer(), nullable=False,
primary_key=True, autoincrement=False)
order = orm.relationship(PurchaseOrder, backref=orm.backref('notes'))
notes = sa.Column(sa.Text(), nullable=True)
def __str__(self):
return self.notes or ""