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