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

(feat) alert on low stock threshold

This commit is contained in:
Sylvain 2022-10-05 15:51:33 +02:00
parent 35dd29c193
commit 8dd4463a14
6 changed files with 33 additions and 0 deletions

View File

@ -72,6 +72,7 @@ class NotificationType
notify_user_order_is_ready
notify_user_order_is_canceled
notify_user_order_is_refunded
notify_admin_low_stock_threshold
]
# deprecated:
# - notify_member_subscribed_plan_is_changed

View File

@ -49,6 +49,13 @@ 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
end

View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
json.title notification.notification_type
json.description t('.low_stock', PRODUCT: t(".#{notification.attached_object.name}")) +
link_to(t('.view_product'), "#!/admin/store/products/#{notification.attached_object.id}/edit")

View File

@ -0,0 +1,11 @@
<%= render 'notifications_mailer/shared/hello', recipient: @recipient %>
<p>
<%= t('.body.low_stock', { PRODUCT: @attached_object.name }) %>
</p>
<p>
<%= t('.body.stocks_state_html', { INTERNAL: @attached_object.stock['internal'], EXTERNAL: @attached_object.stock['external'] }) %>
</p>
<p>
<%=link_to( t('.body.manage_stock'), "#{root_url}#!/admin/store/products/#{@attached_object.id}/edit", target: "_blank" )%>
</p>

View File

@ -365,6 +365,9 @@ en:
import_over: "%{CATEGORY} import is over. "
members: "Members"
view_results: "View results."
notify_admin_low_stock_threshold:
low_stock: "Low stock for %{PRODUCT}. "
view_product: "View the product."
notify_member_about_coupon:
enjoy_a_discount_of_PERCENT_with_code_CODE: "Enjoy a discount of %{PERCENT}% with code %{CODE}"
enjoy_a_discount_of_AMOUNT_with_code_CODE: "Enjoy a discount of %{AMOUNT} with code %{CODE}"

View File

@ -246,6 +246,12 @@ en:
you_made_an_import: "You have initiated an import %{CATEGORY}"
category_members: "of the members"
click_to_view_results: "Click here to view results"
notify_admin_low_stock_threshold:
subject: "Low stock alert"
body:
low_stock: "A new stock movement of %{PRODUCT} has exceeded the low stock threshold."
stocks_state_html: "Current stock status: <ul><li>internal: %{INTERNAL}</li><li>external: %{EXTERNAL}</li></ul>"
manage_stock: "Manage stocks for this product"
notify_member_about_coupon:
subject: "Coupon"
body: