Fixed some errors in articles#sync. Show better error messages.
This commit is contained in:
parent
53518039f1
commit
13e921a632
4 changed files with 45 additions and 19 deletions
|
@ -74,12 +74,12 @@ class ArticlesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# Updates all article of specific supplier
|
# Updates all article of specific supplier
|
||||||
# deletes all articles from params[outlisted_articles]
|
|
||||||
def update_all
|
def update_all
|
||||||
|
invalid_articles = false
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Article.transaction do
|
Article.transaction do
|
||||||
unless params[:articles].blank?
|
unless params[:articles].blank?
|
||||||
invalid_articles = false
|
|
||||||
# Update other article attributes...
|
# Update other article attributes...
|
||||||
@articles = Article.find(params[:articles].keys)
|
@articles = Article.find(params[:articles].keys)
|
||||||
@articles.each do |article|
|
@articles.each do |article|
|
||||||
|
@ -88,25 +88,18 @@ class ArticlesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
raise "Artikel sind fehlerhaft. Bitte überprüfe Deine Eingaben." if invalid_articles
|
raise ActiveRecord::Rollback if invalid_articles # Rollback all changes
|
||||||
end
|
|
||||||
# delete articles
|
|
||||||
if params[:outlisted_articles]
|
|
||||||
params[:outlisted_articles].keys.each {|id| Article.find(id).mark_as_deleted }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if invalid_articles
|
||||||
|
# An error has occurred, transaction has been rolled back.
|
||||||
|
flash.now.alert = 'Artikel sind fehlerhaft. Bitte überprüfen.'
|
||||||
|
render :edit_all
|
||||||
|
else
|
||||||
# Successfully done.
|
# Successfully done.
|
||||||
redirect_to supplier_articles_path(@supplier), notice: "Alle Artikel und Preise wurden aktalisiert"
|
redirect_to supplier_articles_path(@supplier), notice: "Alle Artikel und Preise wurden aktalisiert"
|
||||||
|
|
||||||
rescue => e
|
|
||||||
# An error has occurred, transaction has been rolled back.
|
|
||||||
if params[:sync]
|
|
||||||
flash[:error] = "Es trat ein Fehler beim Aktualisieren des Artikels '#{current_article.name}' auf: #{e.message}"
|
|
||||||
redirect_to(supplier_articles_path(@supplier))
|
|
||||||
else
|
|
||||||
flash.now.alert = e.message
|
|
||||||
render :edit_all
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -232,4 +225,33 @@ class ArticlesController < ApplicationController
|
||||||
redirect_to supplier_articles_path(@supplier), :notice => "Der Katalog ist aktuell."
|
redirect_to supplier_articles_path(@supplier), :notice => "Der Katalog ist aktuell."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Updates, deletes articles when sync form is submitted
|
||||||
|
def update_synchronized
|
||||||
|
begin
|
||||||
|
Article.transaction do
|
||||||
|
# delete articles
|
||||||
|
if params[:outlisted_articles]
|
||||||
|
Article.find(params[:outlisted_articles].keys).each(&:mark_as_deleted)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Update articles
|
||||||
|
params[:articles].each do |id, attrs|
|
||||||
|
Article.find(id).update_attributes! attrs
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Successfully done.
|
||||||
|
redirect_to supplier_articles_path(@supplier), notice: "Alle Artikel und Preise wurden aktalisiert"
|
||||||
|
|
||||||
|
rescue ActiveRecord::RecordInvalid => invalid
|
||||||
|
# An error has occurred, transaction has been rolled back.
|
||||||
|
redirect_to supplier_articles_path(@supplier),
|
||||||
|
alert: "Es trat ein Fehler beim Aktualisieren des Artikels '#{invalid.record.name}' auf: #{invalid.record.errors.full_messages}"
|
||||||
|
|
||||||
|
rescue => error
|
||||||
|
redirect_to supplier_articles_path(@supplier),
|
||||||
|
alert: "Es trat ein Fehler auf: #{error.message}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -158,7 +158,7 @@ class Order < ActiveRecord::Base
|
||||||
goa.save_results!
|
goa.save_results!
|
||||||
# Delete no longer required order-history (group_order_article_quantities) and
|
# Delete no longer required order-history (group_order_article_quantities) and
|
||||||
# TODO: Do we need articles, which aren't ordered? (units_to_order == 0 ?)
|
# TODO: Do we need articles, which aren't ordered? (units_to_order == 0 ?)
|
||||||
goa.group_order_article_quantities.clear
|
#goa.group_order_article_quantities.clear
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
- title 'Artikel mit externer Datenbank synchronisieren'
|
- title 'Artikel mit externer Datenbank synchronisieren'
|
||||||
|
|
||||||
= form_tag update_all_supplier_articles_path(@supplier, :sync => "1") do
|
= form_tag update_synchronized_supplier_articles_path(@supplier) do
|
||||||
%h2 Auslisten ...
|
%h2 Auslisten ...
|
||||||
%p
|
%p
|
||||||
- unless @outlisted_articles.empty?
|
- unless @outlisted_articles.empty?
|
||||||
|
@ -11,6 +11,9 @@
|
||||||
%li
|
%li
|
||||||
= hidden_field_tag "outlisted_articles[#{article.id}]", '1'
|
= hidden_field_tag "outlisted_articles[#{article.id}]", '1'
|
||||||
= article.name
|
= article.name
|
||||||
|
- if article.in_open_order
|
||||||
|
.alert
|
||||||
|
Achtung, #{article.name} wird gerade in einer laufenden Bestellung verwendet. Bitte erst Bestellung anpassen.
|
||||||
- else
|
- else
|
||||||
%i Es müssen keine Artikel gelöscht werden.
|
%i Es müssen keine Artikel gelöscht werden.
|
||||||
%hr/
|
%hr/
|
||||||
|
|
|
@ -117,6 +117,7 @@ Foodsoft::Application.routes.draw do
|
||||||
get :shared
|
get :shared
|
||||||
get :import
|
get :import
|
||||||
post :sync
|
post :sync
|
||||||
|
post :update_synchronized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue