1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

(bug) admin cannot filter product availble in store

This commit is contained in:
Du Peng 2022-10-24 12:34:02 +02:00
parent b3d9c6b3bf
commit 0fddd22df8
3 changed files with 3 additions and 10 deletions

View File

@ -209,7 +209,7 @@ const Store: React.FC<StoreProps> = ({ onError, onSuccess, currentUser, uiRouter
*/
const fetchProducts = async (): Promise<ProductsIndex> => {
try {
const data = await ProductAPI.index(resources.filters.data);
const data = await ProductAPI.index(Object.assign({ store: true }, resources.filters.data));
setCurrentPage(data.page);
setProducts(data.data);
setPageCount(data.total_pages);

View File

@ -42,7 +42,7 @@ export const initialFilters: ProductIndexFilter = {
machines: [],
is_active: false,
is_available: false,
stock_type: 'internal',
stock_type: 'external',
stock_from: 0,
stock_to: 0,
page: 1,

View File

@ -9,7 +9,6 @@ class ProductService
def list(filters, operator)
products = Product.includes(:product_images)
products = filter_by_active(products, filters)
products = filter_by_available(products, filters, operator)
products = filter_by_categories(products, filters)
products = filter_by_machines(products, filters)
products = filter_by_keyword_or_reference(products, filters)
@ -129,12 +128,6 @@ class ProductService
products.where(is_active: state)
end
def filter_by_available(products, filters, operator)
return products if filters[:is_available].blank? || filters[:is_available] == 'false'
filter_by_stock(products, { stock_type: 'external' }, operator)
end
def filter_by_categories(products, filters)
return products if filters[:categories].blank?
@ -159,7 +152,7 @@ class ProductService
products = if filters[:stock_from].to_i.positive?
products.where('(stock ->> ?)::int >= ?', filters[:stock_type], filters[:stock_from])
elsif !operator&.privileged?
elsif filters[:store] == 'true' && filters[:is_available] == 'true'
products.where('(stock ->> ?)::int >= quantity_min', filters[:stock_type])
else
products