From 1757d0978175662c5d7b8c66ea8448075f8e06fc Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 1 Feb 2021 15:30:55 -0600 Subject: [PATCH] Add schema model for Purchase Orders --- corepos/db/office_op/model.py | 118 ++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/corepos/db/office_op/model.py b/corepos/db/office_op/model.py index 0e8bf49..8e24e05 100644 --- a/corepos/db/office_op/model.py +++ b/corepos/db/office_op/model.py @@ -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 ""