mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
(feat) alert on low stock threshold
This commit is contained in:
parent
35dd29c193
commit
8dd4463a14
@ -72,6 +72,7 @@ class NotificationType
|
|||||||
notify_user_order_is_ready
|
notify_user_order_is_ready
|
||||||
notify_user_order_is_canceled
|
notify_user_order_is_canceled
|
||||||
notify_user_order_is_refunded
|
notify_user_order_is_refunded
|
||||||
|
notify_admin_low_stock_threshold
|
||||||
]
|
]
|
||||||
# deprecated:
|
# deprecated:
|
||||||
# - notify_member_subscribed_plan_is_changed
|
# - notify_member_subscribed_plan_is_changed
|
||||||
|
@ -49,6 +49,13 @@ class ProductService
|
|||||||
}
|
}
|
||||||
end || {}
|
end || {}
|
||||||
product.stock = remaining_stock
|
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
|
product
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -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")
|
@ -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>
|
@ -365,6 +365,9 @@ en:
|
|||||||
import_over: "%{CATEGORY} import is over. "
|
import_over: "%{CATEGORY} import is over. "
|
||||||
members: "Members"
|
members: "Members"
|
||||||
view_results: "View results."
|
view_results: "View results."
|
||||||
|
notify_admin_low_stock_threshold:
|
||||||
|
low_stock: "Low stock for %{PRODUCT}. "
|
||||||
|
view_product: "View the product."
|
||||||
notify_member_about_coupon:
|
notify_member_about_coupon:
|
||||||
enjoy_a_discount_of_PERCENT_with_code_CODE: "Enjoy a discount of %{PERCENT}% with code %{CODE}"
|
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}"
|
enjoy_a_discount_of_AMOUNT_with_code_CODE: "Enjoy a discount of %{AMOUNT} with code %{CODE}"
|
||||||
|
@ -246,6 +246,12 @@ en:
|
|||||||
you_made_an_import: "You have initiated an import %{CATEGORY}"
|
you_made_an_import: "You have initiated an import %{CATEGORY}"
|
||||||
category_members: "of the members"
|
category_members: "of the members"
|
||||||
click_to_view_results: "Click here to view results"
|
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:
|
notify_member_about_coupon:
|
||||||
subject: "Coupon"
|
subject: "Coupon"
|
||||||
body:
|
body:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user