From a999b996fbe907dca02a15caf881d4399e652ea6 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 8 Aug 2022 14:39:26 -0500 Subject: [PATCH] Add separate product grid filters for Category Code, Category Name this also fixes a join bug in some edge cases --- tailbone/views/products.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tailbone/views/products.py b/tailbone/views/products.py index 33999781..a9376faf 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -225,6 +225,7 @@ class ProductView(MasterView): def configure_grid(self, g): super(ProductView, self).configure_grid(g) app = self.get_rattail_app() + model = self.model use_buefy = self.get_use_buefy() def join_vendor(q): @@ -335,8 +336,16 @@ class ProductView(MasterView): g.set_label('vendor_code_any', "Vendor Code (any)") # category - g.set_joiner('category', lambda q: q.outerjoin(model.Category)) - g.set_filter('category', model.Category.name) + CategoryByCode = orm.aliased(model.Category) + CategoryByName = orm.aliased(model.Category) + g.set_joiner('category_code', + lambda q: q.outerjoin(CategoryByCode, + CategoryByCode.uuid == model.Product.category_uuid)) + g.set_filter('category_code', CategoryByCode.code) + g.set_joiner('category_name', + lambda q: q.outerjoin(CategoryByName, + CategoryByName.uuid == model.Product.category_uuid)) + g.set_filter('category_name', CategoryByName.name) # family g.set_joiner('family', lambda q: q.outerjoin(model.Family))