Fix products grid query when filter/sort has multiple ProductCost joins

This commit is contained in:
Lance Edgar 2019-01-11 15:14:37 -06:00
parent 1dc21d846e
commit 1dd42e1ab2

View file

@ -147,7 +147,8 @@ class ProductsView(MasterView):
# These aliases enable the grid queries to filter products which may be # These aliases enable the grid queries to filter products which may be
# purchased from *any* vendor, and yet sort by only the "preferred" vendor # purchased from *any* vendor, and yet sort by only the "preferred" vendor
# (since that's what shows up in the grid column). # (since that's what shows up in the grid column).
ProductCostAny = orm.aliased(model.ProductCost) ProductVendorCost = orm.aliased(model.ProductCost)
ProductVendorCostAny = orm.aliased(model.ProductCost)
VendorAny = orm.aliased(model.Vendor) VendorAny = orm.aliased(model.Vendor)
# same, but for prices # same, but for prices
@ -188,17 +189,17 @@ class ProductsView(MasterView):
super(ProductsView, self).configure_grid(g) super(ProductsView, self).configure_grid(g)
def join_vendor(q): def join_vendor(q):
return q.outerjoin(model.ProductCost, return q.outerjoin(self.ProductVendorCost,
sa.and_( sa.and_(
model.ProductCost.product_uuid == model.Product.uuid, self.ProductVendorCost.product_uuid == model.Product.uuid,
model.ProductCost.preference == 1))\ self.ProductVendorCost.preference == 1))\
.outerjoin(model.Vendor) .outerjoin(model.Vendor)
def join_vendor_any(q): def join_vendor_any(q):
return q.outerjoin(self.ProductCostAny, return q.outerjoin(self.ProductVendorCostAny,
self.ProductCostAny.product_uuid == model.Product.uuid)\ self.ProductVendorCostAny.product_uuid == model.Product.uuid)\
.outerjoin(self.VendorAny, .outerjoin(self.VendorAny,
self.VendorAny.uuid == self.ProductCostAny.vendor_uuid) self.VendorAny.uuid == self.ProductVendorCostAny.vendor_uuid)
ProductCostCode = orm.aliased(model.ProductCost) ProductCostCode = orm.aliased(model.ProductCost)
ProductCostCodeAny = orm.aliased(model.ProductCost) ProductCostCodeAny = orm.aliased(model.ProductCost)