| @@ 5-39 (lines=35) @@ | ||
| 2 | from . import vendor |
|
| 3 | from . import box |
|
| 4 | ||
| 5 | class BoxVendor(Base): |
|
| 6 | __tablename__ = 'box_vendors' |
|
| 7 | ||
| 8 | id = Column(Integer, primary_key=True, nullable=False) |
|
| 9 | vendor_id = Column(Integer, ForeignKey("vendors.id"), nullable=False) |
|
| 10 | box_id = Column(Integer, ForeignKey("boxes.id"), nullable=False) |
|
| 11 | item_number = Column(String(255), nullable=False) |
|
| 12 | ||
| 13 | enabled = Column(Boolean, default=True, nullable=False) |
|
| 14 | ||
| 15 | vendor = relationship( |
|
| 16 | vendor.Vendor, |
|
| 17 | primaryjoin="and_(BoxVendor.vendor_id==Vendor.id, BoxVendor.enabled==True)", |
|
| 18 | backref="boxes" |
|
| 19 | ) |
|
| 20 | box = relationship( |
|
| 21 | box.Box, |
|
| 22 | primaryjoin="and_(BoxVendor.box_id==Box.id, BoxVendor.enabled==True)", |
|
| 23 | backref="vendors" |
|
| 24 | ) |
|
| 25 | ||
| 26 | ||
| 27 | def __init__(self, vendor, box, item_number, enabled=True): |
|
| 28 | self.vendor_id = vendor.id |
|
| 29 | self.box_id = box.id |
|
| 30 | self.item_number = item_number |
|
| 31 | self.enabled = enabled |
|
| 32 | ||
| 33 | @classmethod |
|
| 34 | def from_id(cls, id): |
|
| 35 | return DBSession.query(cls).filter(cls.id == id).one() |
|
| 36 | ||
| 37 | @classmethod |
|
| 38 | def from_number_fuzzy(cls, number): |
|
| 39 | return DBSession.query(cls).filter(cls.item_number.like('%{}%'.format(number))).all() |
|
| 40 | ||
| @@ 5-38 (lines=34) @@ | ||
| 2 | from . import vendor |
|
| 3 | from . import item |
|
| 4 | ||
| 5 | class ItemVendor(Base): |
|
| 6 | __tablename__ = 'item_vendors' |
|
| 7 | ||
| 8 | id = Column(Integer, primary_key=True, nullable=False) |
|
| 9 | vendor_id = Column(Integer, ForeignKey("vendors.id"), nullable=False) |
|
| 10 | item_id = Column(Integer, ForeignKey("items.id"), nullable=False) |
|
| 11 | item_number = Column(String(255), nullable=False) |
|
| 12 | ||
| 13 | enabled = Column(Boolean, default=True, nullable=False) |
|
| 14 | ||
| 15 | vendor = relationship( |
|
| 16 | vendor.Vendor, |
|
| 17 | primaryjoin="and_(ItemVendor.vendor_id==Vendor.id, ItemVendor.enabled==True)", |
|
| 18 | backref="items" |
|
| 19 | ) |
|
| 20 | item = relationship( |
|
| 21 | item.Item, |
|
| 22 | primaryjoin="and_(ItemVendor.item_id==Item.id, ItemVendor.enabled==True)", |
|
| 23 | backref="vendors" |
|
| 24 | ) |
|
| 25 | ||
| 26 | def __init__(self, vendor, item, item_number, enabled=True): |
|
| 27 | self.vendor_id = vendor.id |
|
| 28 | self.item_id = item.id |
|
| 29 | self.item_number = item_number |
|
| 30 | self.enabled = enabled |
|
| 31 | ||
| 32 | @classmethod |
|
| 33 | def from_id(cls, id): |
|
| 34 | return DBSession.query(cls).filter(cls.id == id).one() |
|
| 35 | ||
| 36 | @classmethod |
|
| 37 | def from_number_fuzzy(cls, number): |
|
| 38 | return DBSession.query(cls).filter(cls.item_number.like('%{}%'.format(number))).all() |
|
| 39 | ||
| @@ 5-31 (lines=27) @@ | ||
| 2 | ||
| 3 | from sqlalchemy_utils import ArrowType |
|
| 4 | ||
| 5 | class RequestPost(Base): |
|
| 6 | __tablename__ = 'request_posts' |
|
| 7 | ||
| 8 | id = Column(Integer, primary_key=True, nullable=False) |
|
| 9 | timestamp = Column(ArrowType, nullable=False, default=datetime.datetime.utcnow) |
|
| 10 | request_id = Column(Integer, ForeignKey("requests.id"), nullable=False) |
|
| 11 | user_id = Column(Integer, ForeignKey("users.id"), nullable=False) |
|
| 12 | post = Column(Text) |
|
| 13 | # Allow admin users to post as users or admins by tracking the view that the post is posted from |
|
| 14 | staff_post = Column(Boolean, default=False, nullable=False) |
|
| 15 | deleted = Column(Boolean, default=False, nullable=False) |
|
| 16 | ||
| 17 | def __init__(self, request, user, post, staff_post=False, deleted=False): |
|
| 18 | self.request_id = request.id |
|
| 19 | self.user_id = user.id |
|
| 20 | self.post = post |
|
| 21 | self.staff_post = staff_post |
|
| 22 | self.deleted = deleted |
|
| 23 | ||
| 24 | @classmethod |
|
| 25 | def from_id(cls, id): |
|
| 26 | return DBSession.query(cls).filter(cls.id == id).one() |
|
| 27 | ||
| 28 | @classmethod |
|
| 29 | def all(cls): |
|
| 30 | return DBSession.query(cls).filter(cls.deleted==False)\ |
|
| 31 | .order_by(desc(cls.timestamp))\ |
|
| 32 | .all() |
|
| 33 | ||
| 34 | ||
| @@ 908-943 (lines=36) @@ | ||
| 905 | self.wholesale = wholesale |
|
| 906 | self.coupon_amount = coupon |
|
| 907 | self.sales_tax = sales_tax |
|
| 908 | self.bottle_deposit = bottle_deposit |
|
| 909 | ||
| 910 | ||
| 911 | class InventoryLineItem(SubTransaction): |
|
| 912 | __mapper_args__ = {'polymorphic_identity': 'inventorylineitem'} |
|
| 913 | quantity_predicted = synonym(SubTransaction.quantity) |
|
| 914 | quantity_counted = Column(Integer) |
|
| 915 | ||
| 916 | def __init__(self, transaction, amount, item, quantity_predicted, quantity_counted, wholesale): |
|
| 917 | SubTransaction.__init__(self, transaction, amount, item.id, quantity_predicted, wholesale) |
|
| 918 | self.quantity_counted = quantity_counted |
|
| 919 | ||
| 920 | ||
| 921 | ||
| 922 | ################################################################################ |
|
| 923 | ## SUBSUB TRANSACTIONS |
|
| 924 | ################################################################################ |
|
| 925 | ||
| 926 | # This is for tracking which items were in which boxes when we restocked |
|
| 927 | ||
| 928 | class SubSubTransaction(Base): |
|
| 929 | __tablename__ = "subsubtransactions" |
|
| 930 | ||
| 931 | id = Column(Integer, primary_key=True, nullable=False) |
|
| 932 | subtransaction_id = Column(Integer, ForeignKey("subtransactions.id"), nullable=False) |
|
| 933 | type = Column(Enum("restocklineboxitem", |
|
| 934 | name="subsubtransaction_type"), nullable=False) |
|
| 935 | item_id = Column(Integer, ForeignKey("items.id"), nullable=True) |
|
| 936 | quantity = Column(Integer, nullable=False) |
|
| 937 | ||
| 938 | subtransaction = relationship(SubTransaction, backref="subsubtransactions", cascade="all") |
|
| 939 | item = relationship(item.Item, backref="subsubtransactions") |
|
| 940 | ||
| 941 | __mapper_args__ = {'polymorphic_on': type} |
|
| 942 | ||
| 943 | def __init__(self, subtransaction, item_id, quantity): |
|
| 944 | self.subtransaction_id = subtransaction.id |
|
| 945 | self.item_id = item_id |
|
| 946 | self.quantity = quantity |
|