From 4a96ccca75fbd7038c91f461a934b40f88ba8827 2012-08-20 11:18:36 From: Lance Edgar Date: 2012-08-20 11:18:36 Subject: [PATCH] add Product.cost, Product.vendor --- diff --git a/rattail/db/extension/model.py b/rattail/db/extension/model.py index ae97b240874f5e4559170f608e639307aff476e3..110f3736ff094bce267e6c1e459af600693e3e7c 100644 --- a/rattail/db/extension/model.py +++ b/rattail/db/extension/model.py @@ -808,6 +808,7 @@ class Product(Base): subdepartment = relationship(Subdepartment) category = relationship(Category) brand = relationship(Brand) + costs = relationship(ProductCost, backref='product', collection_class=ordering_list('preference', count_from=1), order_by=ProductCost.preference) @@ -834,6 +835,26 @@ Product.current_price = relationship( lazy='joined', post_update=True) +Product.cost = relationship( + ProductCost, + primaryjoin=and_( + ProductCost.product_uuid == Product.uuid, + ProductCost.preference == 1, + ), + uselist=False, + viewonly=True) + +Product.vendor = relationship( + Vendor, + secondary=ProductCost.__table__, + primaryjoin=and_( + ProductCost.product_uuid == Product.uuid, + ProductCost.preference == 1, + ), + secondaryjoin=Vendor.uuid == ProductCost.vendor_uuid, + uselist=False, + viewonly=True) + class EmployeeEmailAddress(EmailAddress): """