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

coupon safe destroy

This commit is contained in:
Sylvain 2016-08-08 12:25:27 +02:00
parent 13e84f434d
commit 35b324e108
5 changed files with 21 additions and 5 deletions

View File

@ -350,7 +350,10 @@ Application.Controllers.controller "EditPricingController", ["$scope", "$state",
, (error) ->
console.error('[EditPricingController::deleteCoupon] Error: '+error.statusText) if error.statusText
growl.error(_t('unable_to_delete_the_specified_coupon_an_error_occurred'))
if error.status == 422
growl.error(_t('unable_to_delete_the_specified_coupon_already_in_use'))
else
growl.error(_t('unable_to_delete_the_specified_coupon_an_unexpected_error_occurred'))

View File

@ -30,8 +30,11 @@ class API::CouponsController < API::ApiController
def destroy
authorize Coupon
@coupon.destroy
head :no_content
if @coupon.safe_destroy
head :no_content
else
head :unprocessable_entity
end
end
private

View File

@ -7,4 +7,12 @@ class Coupon < ActiveRecord::Base
validates :percent_off, presence: true
validates :percent_off, :inclusion => 0..100
def safe_destroy
if self.invoices.size == 0
destroy
else
false
end
end
end

View File

@ -155,7 +155,8 @@ en:
active: "Active"
do_you_really_want_to_delete_this_coupon: "Do you really want to delete this coupon?"
coupon_was_successfully_deleted: "Coupon was successfully deleted."
unable_to_delete_the_specified_coupon_an_error_occurred: "Unable to delete the specified coupon, an error occurred."
unable_to_delete_the_specified_coupon_already_in_use: "Unable to delete the specified coupon: it is already used with some invoices."
unable_to_delete_the_specified_coupon_an_unexpected_error_occurred: "Unable to delete the specified coupon: an unexpected error occurred."
coupons_new:
# ajouter un code promotionnel

View File

@ -155,7 +155,8 @@ fr:
active: "Actif"
do_you_really_want_to_delete_this_coupon: "Êtes-vous sûr(e) de vouloir supprimer ce code promotionnel ?"
coupon_was_successfully_deleted: "Le code promotionnel a bien été supprimé."
unable_to_delete_the_specified_coupon_an_error_occurred: "Impossible de supprimer le code promotionnel, une erreur s'est produite."
unable_to_delete_the_specified_coupon_already_in_use: "Impossible de supprimer le code promotionnel : il est utilisé dans des factures."
unable_to_delete_the_specified_coupon_an_unexpected_error_occurred: "Impossible de supprimer le code promotionnel : une erreur inattendue s'est produite."
coupons_new:
# ajouter un code promotionnel