mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
(bug) fix product cannot update low stock alert
This commit is contained in:
parent
5de91acf88
commit
9ddc21619b
@ -50,7 +50,8 @@ class ProductService
|
|||||||
}
|
}
|
||||||
end || {}
|
end || {}
|
||||||
product.stock = remaining_stock
|
product.stock = remaining_stock
|
||||||
notify_on_low_stock(product, stock_movements)
|
notify_on_low_stock(product) if product.low_stock_alert
|
||||||
|
product
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(product_params, stock_movement_params = [])
|
def create(product_params, stock_movement_params = [])
|
||||||
@ -188,12 +189,11 @@ class ProductService
|
|||||||
movements.where(reason: filters[:reason])
|
movements.where(reason: filters[:reason])
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_on_low_stock(product, stock_movements)
|
def notify_on_low_stock(product)
|
||||||
return product unless product.low_stock_threshold
|
return product unless product.low_stock_threshold
|
||||||
|
|
||||||
affected_stocks = stock_movements&.map { |m| m[:stock_type] }&.uniq
|
if (product.stock['internal'] < product.low_stock_threshold) ||
|
||||||
if (remaining_stock[:internal] < product.low_stock_threshold && affected_stocks&.include?('internal')) ||
|
(product.stock['external'] < product.low_stock_threshold)
|
||||||
(remaining_stock[:external] < product.low_stock_threshold && affected_stocks&.include?('external'))
|
|
||||||
NotificationCenter.call type: 'notify_admin_low_stock_threshold',
|
NotificationCenter.call type: 'notify_admin_low_stock_threshold',
|
||||||
receiver: User.admins_and_managers,
|
receiver: User.admins_and_managers,
|
||||||
attached_object: product
|
attached_object: product
|
||||||
|
Loading…
x
Reference in New Issue
Block a user