1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-29 18:52:22 +01:00

(bug) show explicit error message when unable to delete a product

This commit is contained in:
Sylvain 2022-10-05 13:50:57 +02:00
parent 6f14bdadf3
commit 35dd29c193
3 changed files with 5 additions and 2 deletions

View File

@ -1,3 +1,5 @@
# Raised when delete a product if this product has used in order
# frozen_string_literal: true
# Raised when deleting a product, if this product is used in orders
class CannotDeleteProductError < StandardError
end

View File

@ -69,7 +69,7 @@ class ProductService
def destroy(product)
used_in_order = OrderItem.joins(:order).where.not('orders.state' => 'cart')
.exists?(orderable: product)
raise CannotDeleteProductError if used_in_order
raise CannotDeleteProductError, I18n.t('errors.messages.product_in_use') if used_in_order
ActiveRecord::Base.transaction do
orders_with_product = Order.joins(:order_items).where(state: 'cart').where('order_items.orderable': product)

View File

@ -46,6 +46,7 @@ en:
gateway_error: "Payement gateway error: %{MESSAGE}"
gateway_amount_too_small: "Payments under %{AMOUNT} are not supported. Please order directly at the reception."
gateway_amount_too_large: "Payments above %{AMOUNT} are not supported. Please order directly at the reception."
product_in_use: "This product have already been ordered"
apipie:
api_documentation: "API Documentation"
code: "HTTP code"