Fix vendor filter/sort issues in products grid.
This commit is contained in:
parent
0d65691952
commit
e4ef46d4fc
|
@ -27,7 +27,7 @@ Product Views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from sqlalchemy import and_
|
from sqlalchemy import and_
|
||||||
from sqlalchemy.orm import joinedload
|
from sqlalchemy.orm import joinedload, aliased
|
||||||
|
|
||||||
from webhelpers.html.tags import link_to
|
from webhelpers.html.tags import link_to
|
||||||
|
|
||||||
|
@ -60,18 +60,32 @@ class ProductsGrid(SearchableAlchemyGridView):
|
||||||
config_prefix = 'products'
|
config_prefix = 'products'
|
||||||
sort = 'description'
|
sort = 'description'
|
||||||
|
|
||||||
|
# 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 = aliased(ProductCost)
|
||||||
|
VendorAny = aliased(Vendor)
|
||||||
|
|
||||||
def join_map(self):
|
def join_map(self):
|
||||||
|
|
||||||
# def join_vendor(q):
|
def join_vendor(q):
|
||||||
# q = q.outerjoin(
|
q = q.outerjoin(
|
||||||
# ProductCost,
|
ProductCost,
|
||||||
# ProductCost.product_uuid == Product.uuid,
|
and_(
|
||||||
# and_(
|
ProductCost.product_uuid == Product.uuid,
|
||||||
# ProductCost.product_uuid == Product.uuid,
|
ProductCost.preference == 1,
|
||||||
# ProductCost.preference == 1,
|
))
|
||||||
# ))
|
q = q.outerjoin(Vendor)
|
||||||
# q = q.outerjoin(Vendor)
|
return q
|
||||||
# return q
|
|
||||||
|
def join_vendor_any(q):
|
||||||
|
q = q.outerjoin(
|
||||||
|
self.ProductCostAny,
|
||||||
|
self.ProductCostAny.product_uuid == Product.uuid)
|
||||||
|
q = q.outerjoin(
|
||||||
|
self.VendorAny,
|
||||||
|
self.VendorAny.uuid == self.ProductCostAny.vendor_uuid)
|
||||||
|
return q
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'brand':
|
'brand':
|
||||||
|
@ -88,10 +102,10 @@ class ProductsGrid(SearchableAlchemyGridView):
|
||||||
'current_price':
|
'current_price':
|
||||||
lambda q: q.outerjoin(ProductPrice,
|
lambda q: q.outerjoin(ProductPrice,
|
||||||
ProductPrice.uuid == Product.current_price_uuid),
|
ProductPrice.uuid == Product.current_price_uuid),
|
||||||
# 'vendor':
|
'vendor':
|
||||||
# join_vendor,
|
join_vendor,
|
||||||
'vendor_any':
|
'vendor_any':
|
||||||
lambda q: q.outerjoin(ProductCost, ProductCost.product_uuid == Product.uuid).outerjoin(Vendor),
|
join_vendor_any,
|
||||||
'code':
|
'code':
|
||||||
lambda q: q.outerjoin(ProductCode),
|
lambda q: q.outerjoin(ProductCode),
|
||||||
}
|
}
|
||||||
|
@ -126,8 +140,8 @@ class ProductsGrid(SearchableAlchemyGridView):
|
||||||
brand=self.filter_ilike(Brand.name),
|
brand=self.filter_ilike(Brand.name),
|
||||||
department=self.filter_ilike(Department.name),
|
department=self.filter_ilike(Department.name),
|
||||||
subdepartment=self.filter_ilike(Subdepartment.name),
|
subdepartment=self.filter_ilike(Subdepartment.name),
|
||||||
# vendor=self.filter_ilike(Vendor.name),
|
vendor=self.filter_ilike(Vendor.name),
|
||||||
vendor_any=self.filter_ilike(Vendor.name),
|
vendor_any=self.filter_ilike(self.VendorAny.name),
|
||||||
code=self.filter_ilike(ProductCode.code))
|
code=self.filter_ilike(ProductCode.code))
|
||||||
|
|
||||||
def filter_config(self):
|
def filter_config(self):
|
||||||
|
@ -141,6 +155,7 @@ class ProductsGrid(SearchableAlchemyGridView):
|
||||||
filter_type_description='lk',
|
filter_type_description='lk',
|
||||||
include_filter_department=True,
|
include_filter_department=True,
|
||||||
filter_type_department='lk',
|
filter_type_department='lk',
|
||||||
|
filter_label_vendor="Vendor (preferred)",
|
||||||
include_filter_vendor_any=True,
|
include_filter_vendor_any=True,
|
||||||
filter_label_vendor_any="Vendor (any)",
|
filter_label_vendor_any="Vendor (any)",
|
||||||
filter_type_vendor_any='lk')
|
filter_type_vendor_any='lk')
|
||||||
|
|
Loading…
Reference in a new issue