From 1dd42e1ab2de42174678570a501b6196c4d2a69d Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 11 Jan 2019 15:14:37 -0600 Subject: [PATCH] Fix products grid query when filter/sort has multiple ProductCost joins --- tailbone/views/products.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tailbone/views/products.py b/tailbone/views/products.py index bf5a974d..9ee7a60c 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -147,7 +147,8 @@ class ProductsView(MasterView): # These aliases enable the grid queries to filter products which may be # purchased from *any* vendor, and yet sort by only the "preferred" vendor # (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) # same, but for prices @@ -188,17 +189,17 @@ class ProductsView(MasterView): super(ProductsView, self).configure_grid(g) def join_vendor(q): - return q.outerjoin(model.ProductCost, + return q.outerjoin(self.ProductVendorCost, sa.and_( - model.ProductCost.product_uuid == model.Product.uuid, - model.ProductCost.preference == 1))\ + self.ProductVendorCost.product_uuid == model.Product.uuid, + self.ProductVendorCost.preference == 1))\ .outerjoin(model.Vendor) def join_vendor_any(q): - return q.outerjoin(self.ProductCostAny, - self.ProductCostAny.product_uuid == model.Product.uuid)\ + return q.outerjoin(self.ProductVendorCostAny, + self.ProductVendorCostAny.product_uuid == model.Product.uuid)\ .outerjoin(self.VendorAny, - self.VendorAny.uuid == self.ProductCostAny.vendor_uuid) + self.VendorAny.uuid == self.ProductVendorCostAny.vendor_uuid) ProductCostCode = orm.aliased(model.ProductCost) ProductCostCodeAny = orm.aliased(model.ProductCost)