mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +01:00
(bug) ArgumentError (comparison of Integer with nil failed)
this crash occured when creating/updating a product without activating the low stock alert
This commit is contained in:
parent
3a9344103c
commit
6a0b896815
@ -8,7 +8,7 @@ class Orders::OrderService
|
||||
ORDERS_PER_PAGE = 20
|
||||
|
||||
def list(filters, current_user)
|
||||
orders = Order.includes(statistic_profile: [:user]).where(nil)
|
||||
orders = Order.includes(statistic_profile: [user: [:profile]]).where(nil)
|
||||
orders = filter_by_user(orders, filters, current_user)
|
||||
orders = filter_by_reference(orders, filters, current_user)
|
||||
orders = filter_by_state(orders, filters)
|
||||
|
@ -50,14 +50,7 @@ class ProductService
|
||||
}
|
||||
end || {}
|
||||
product.stock = remaining_stock
|
||||
affected_stocks = stock_movements&.map { |m| m[:stock_type] }&.uniq
|
||||
if (remaining_stock[:internal] < product.low_stock_threshold && affected_stocks&.include?('internal')) ||
|
||||
(remaining_stock[:external] < product.low_stock_threshold && affected_stocks&.include?('external'))
|
||||
NotificationCenter.call type: 'notify_admin_low_stock_threshold',
|
||||
receiver: User.admins_and_managers,
|
||||
attached_object: product
|
||||
end
|
||||
product
|
||||
notify_on_low_stock(product, stock_movements)
|
||||
end
|
||||
|
||||
def create(product_params, stock_movement_params = [])
|
||||
@ -173,5 +166,18 @@ class ProductService
|
||||
|
||||
movements.where(reason: filters[:reason])
|
||||
end
|
||||
|
||||
def notify_on_low_stock(product, stock_movements)
|
||||
return product unless product.low_stock_threshold
|
||||
|
||||
affected_stocks = stock_movements&.map { |m| m[:stock_type] }&.uniq
|
||||
if (remaining_stock[:internal] < product.low_stock_threshold && affected_stocks&.include?('internal')) ||
|
||||
(remaining_stock[:external] < product.low_stock_threshold && affected_stocks&.include?('external'))
|
||||
NotificationCenter.call type: 'notify_admin_low_stock_threshold',
|
||||
receiver: User.admins_and_managers,
|
||||
attached_object: product
|
||||
end
|
||||
product
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user