From 28644dc33406eec4b023fd340662f80f9cc1f35c Mon Sep 17 00:00:00 2001 From: Julius Date: Tue, 8 Oct 2013 19:58:11 +0200 Subject: [PATCH] Force update in Order#finish; rescue if error raised --- app/controllers/orders_controller.rb | 2 ++ app/models/order.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 7fba518a..e1cd7698 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -98,6 +98,8 @@ class OrdersController < ApplicationController order = Order.find(params[:id]) order.finish!(@current_user) redirect_to order, notice: I18n.t('orders.finish.notice') + rescue => error + redirect_to orders_url, alert: I18n.t('errors.general_msg', :msg => error.message) end # Renders the fax-text-file diff --git a/app/models/order.rb b/app/models/order.rb index f4545d02..057c0768 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -155,7 +155,7 @@ class Order < ActiveRecord::Base unless finished? Order.transaction do # set new order state (needed by notify_order_finished) - update_attributes(:state => 'finished', :ends => Time.now, :updated_by => user) + update_attributes!(:state => 'finished', :ends => Time.now, :updated_by => user) # Update order_articles. Save the current article_price to keep price consistency # Also save results for each group_order_result