@@ 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 | quantity_counted = Column(Integer) |
|
906 | ||
907 | def __init__(self, transaction, amount, item, quantity_predicted, quantity_counted, wholesale): |
|
908 | SubTransaction.__init__(self, transaction, amount, item.id, quantity_predicted, wholesale) |
|
909 | self.quantity_counted = quantity_counted |
|
910 | ||
911 | ||
912 | ||
913 | ################################################################################ |
|
914 | ## SUBSUB TRANSACTIONS |
|
915 | ################################################################################ |
|
916 | ||
917 | # This is for tracking which items were in which boxes when we restocked |
|
918 | ||
919 | class SubSubTransaction(Base): |
|
920 | __tablename__ = "subsubtransactions" |
|
921 | ||
922 | id = Column(Integer, primary_key=True, nullable=False) |
|
923 | subtransaction_id = Column(Integer, ForeignKey("subtransactions.id"), nullable=False) |
|
924 | type = Column(Enum("restocklineboxitem", |
|
925 | name="subsubtransaction_type"), nullable=False) |
|
926 | item_id = Column(Integer, ForeignKey("items.id"), nullable=True) |
|
927 | quantity = Column(Integer, nullable=False) |
|
928 | ||
929 | subtransaction = relationship(SubTransaction, backref="subsubtransactions", cascade="all") |
|
930 | item = relationship(item.Item, backref="subsubtransactions") |
|
931 | ||
932 | __mapper_args__ = {'polymorphic_on': type} |
|
933 | ||
934 | def __init__(self, subtransaction, item_id, quantity): |
|
935 | self.subtransaction_id = subtransaction.id |
|
936 | self.item_id = item_id |
|
937 | self.quantity = quantity |
|
938 | ||
939 | def __getattr__(self, name): |
|
940 | if name == 'deleted': |
|
941 | return self.subtransaction.transaction.event.deleted |
|
942 | else: |
|
943 | raise AttributeError |
|
944 | ||
945 | @classmethod |
|
946 | @limitable_all |