1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

(bug) product low stock notification

This commit is contained in:
Sylvain 2022-12-28 11:01:05 +01:00
parent 5ff022d493
commit 7cd689b92c
5 changed files with 12 additions and 9 deletions

View File

@ -24,6 +24,7 @@
- Fix a bug: unable to access in-system notifications if a slot was cancelled
- Fix a bug: feature tour in admin/settings is broken
- Fix a bug: clearing the new expiration date field in the offer days modal result in errors
- Fix a bug: low stock notification is always sent if one of the stocks has reached the threshold
- Updated react-modal to 3.16.1
- Updated tiptap editor and its dependencies to 2.0.0-beta.204
- [TODO DEPLOY] `rails db:seed`

View File

@ -50,7 +50,7 @@ class ProductService
}
end || {}
product.stock = remaining_stock
notify_on_low_stock(product) if product.low_stock_alert
notify_on_low_stock(product, stock_movements)
product
end
@ -187,11 +187,13 @@ class ProductService
movements.where(reason: filters[:reason])
end
def notify_on_low_stock(product)
def notify_on_low_stock(product, stock_movements = nil)
return product unless product.low_stock_alert
return product unless product.low_stock_threshold
if (product.stock['internal'] <= product.low_stock_threshold) ||
(product.stock['external'] <= product.low_stock_threshold)
affected_stocks = stock_movements&.map { |m| m[:stock_type] }&.uniq
if (product.stock['internal'] <= product.low_stock_threshold && affected_stocks&.include?('internal')) ||
(product.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

View File

@ -49,7 +49,7 @@ class Subscriptions::FreeExtensionTest < ActionDispatch::IntegrationTest
# Check notification was sent to the user
notification = Notification.find_by(
notification_type_id: NotificationType.find_by(name: 'notify_member_subscription_extended'),
notification_type_id: NotificationType.find_by_name('notify_member_subscription_extended'), # rubocop:disable Rails/DynamicFindBy
attached_object_type: 'Subscription',
attached_object_id: subscription[:id]
)

View File

@ -64,7 +64,7 @@ class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest
# Check notification was sent to the user
notification = Notification.find_by(
notification_type_id: NotificationType.find_by(name: 'notify_member_subscribed_plan'),
notification_type_id: NotificationType.find_by_name('notify_member_subscribed_plan'), # rubocop:disable Rails/DynamicFindBy
attached_object_type: 'Subscription',
attached_object_id: subscription[:id]
)
@ -118,7 +118,7 @@ class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest
# Check notification was sent to the user
notification = Notification.find_by(
notification_type_id: NotificationType.find_by(name: 'notify_member_subscribed_plan'),
notification_type_id: NotificationType.find_by_name('notify_member_subscribed_plan'), # rubocop:disable Rails/DynamicFindBy
attached_object_type: 'Subscription',
attached_object_id: subscription[:id]
)

View File

@ -25,8 +25,8 @@ class Cart::AddItemServiceTest < ActiveSupport::TestCase
assert_equal cart.order_items.first.quantity, @caisse_en_bois.quantity_min
end
test 'add two product to cart' do
cart = Cart::AddItemService.new.call(@cart, @panneaux, 10)
test 'add two products to the cart' do
Cart::AddItemService.new.call(@cart, @panneaux, 10)
cart = Cart::AddItemService.new.call(@cart, @caisse_en_bois)
assert_equal cart.total, (@caisse_en_bois.amount * 5) + (@panneaux.amount * 10)
assert_equal cart.order_items.length, 2