1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-17 11:54:22 +01:00

(bug) fix product cannot update low stock alert

This commit is contained in:
Du Peng 2022-10-13 14:42:32 +02:00
parent 5de91acf88
commit 9ddc21619b

View File

@ -50,7 +50,8 @@ class ProductService
}
end || {}
product.stock = remaining_stock
notify_on_low_stock(product, stock_movements)
notify_on_low_stock(product) if product.low_stock_alert
product
end
def create(product_params, stock_movement_params = [])
@ -188,12 +189,11 @@ class ProductService
movements.where(reason: filters[:reason])
end
def notify_on_low_stock(product, stock_movements)
def notify_on_low_stock(product)
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'))
if (product.stock['internal'] < product.low_stock_threshold) ||
(product.stock['external'] < product.low_stock_threshold)
NotificationCenter.call type: 'notify_admin_low_stock_threshold',
receiver: User.admins_and_managers,
attached_object: product