From 7e0a4acf596fa773429e7c0eb496b524699629c6 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Tue, 26 Feb 2013 10:05:37 +0100 Subject: [PATCH 01/31] No need to track specific ruby version. Already defined in Gemfile. --- .rbenv-version | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .rbenv-version diff --git a/.rbenv-version b/.rbenv-version deleted file mode 100644 index 546d4d8a..00000000 --- a/.rbenv-version +++ /dev/null @@ -1 +0,0 @@ -1.9.3-p327 \ No newline at end of file From 6bf3b241e6a34b7ce5a5d704df5dc1573ad40951 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Wed, 6 Mar 2013 14:19:06 +0100 Subject: [PATCH 02/31] Do not subtract articles in open orders when calculating quantity. --- app/models/stock_article.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/stock_article.rb b/app/models/stock_article.rb index 6050c8c4..71679e93 100644 --- a/app/models/stock_article.rb +++ b/app/models/stock_article.rb @@ -16,7 +16,7 @@ class StockArticle < Article # Check for unclosed orders and substract its ordered quantity def quantity_available quantity - OrderArticle.where(article_id: id). - joins(:order).where("orders.state = 'open' OR orders.state = 'finished'").sum(:units_to_order) + joins(:order).where("orders.state = 'finished'").sum(:units_to_order) end def self.stock_value From 93a99c45d82331cf32583ddf97178f7b769f9fbd Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Thu, 7 Mar 2013 20:39:35 +0100 Subject: [PATCH 03/31] Revert "Do not subtract articles in open orders when calculating quantity." This reverts commit 6bf3b241e6a34b7ce5a5d704df5dc1573ad40951. --- app/models/stock_article.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/stock_article.rb b/app/models/stock_article.rb index 71679e93..6050c8c4 100644 --- a/app/models/stock_article.rb +++ b/app/models/stock_article.rb @@ -16,7 +16,7 @@ class StockArticle < Article # Check for unclosed orders and substract its ordered quantity def quantity_available quantity - OrderArticle.where(article_id: id). - joins(:order).where("orders.state = 'finished'").sum(:units_to_order) + joins(:order).where("orders.state = 'open' OR orders.state = 'finished'").sum(:units_to_order) end def self.stock_value From 63d8a3a1a63cfac4a3949576464cb21fdae8da13 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Thu, 7 Mar 2013 20:43:02 +0100 Subject: [PATCH 04/31] Do not exclude ordered articles (with zero quantity) when editing orders. --- app/models/article.rb | 4 ++++ app/models/order.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/article.rb b/app/models/article.rb index 09f17fa4..85c02577 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -48,6 +48,10 @@ class Article < ActiveRecord::Base order_article ? order_article.order : nil end memoize :in_open_order + + def ordered?(order) + order.order_articles.where(article_id: id).where('quantity > 0').one? + end # this method checks, if the shared_article has been changed # unequal attributes will returned in array diff --git a/app/models/order.rb b/app/models/order.rb index 6e48756c..a59d20f7 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -41,7 +41,7 @@ class Order < ActiveRecord::Base if stockit? StockArticle.available.all(:include => :article_category, :order => 'article_categories.name, articles.name').reject{ |a| - a.quantity_available <= 0 + a.quantity_available <= 0 and not a.ordered?(self) }.group_by { |a| a.article_category.name } else supplier.articles.available.all.group_by { |a| a.article_category.name } From 2f109c376df1632599ee911ebe0405dfb3027b02 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Tue, 26 Feb 2013 10:59:05 +0100 Subject: [PATCH 05/31] Fixed bug when submitting huge forms. (stock taking etc) --- config/initializers/rack.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 config/initializers/rack.rb diff --git a/config/initializers/rack.rb b/config/initializers/rack.rb new file mode 100644 index 00000000..30970ec9 --- /dev/null +++ b/config/initializers/rack.rb @@ -0,0 +1,3 @@ +# Increase key space for post request. +# Warning, this is dangerous. See http://stackoverflow.com/questions/12243694/getting-error-exceeded-available-parameter-key-space +Rack::Utils.key_space_limit = 262144 From 50873addf87a69de3012c00cfd5d2eecd1749f5c Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sat, 9 Mar 2013 16:46:33 +0100 Subject: [PATCH 06/31] Fixed deleting of articles. Added missing id. --- app/views/articles/_article.html.haml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/views/articles/_article.html.haml b/app/views/articles/_article.html.haml index ac2679e1..ed22dec0 100644 --- a/app/views/articles/_article.html.haml +++ b/app/views/articles/_article.html.haml @@ -1,4 +1,4 @@ -%tr{class: row_classes(article)} +%tr{class: row_classes(article)}[article] %td= check_box_tag 'selected_articles[]', article.id.to_s, false, {:id => "checkbox_#{article.id}", 'data-ignore-onchange' => true} %td{'data-check-this' => "#checkbox_#{article.id}", :class => 'click-me'}= article.name %td= article.origin @@ -14,6 +14,4 @@ %td= link_to "Bearbeiten", edit_supplier_article_path(@supplier, article), :remote => true, class: 'btn btn-mini' %td= link_to "Löschen", [@supplier, article], - :method => :delete, :confirm => 'Bist du sicher?', :remote => true, class: 'btn btn-mini btn-danger' - - \ No newline at end of file + :method => :delete, :confirm => 'Bist du sicher?', :remote => true, class: 'btn btn-mini btn-danger' \ No newline at end of file From 762d52989413e8571d86cedf5e884ddf29a8a0d7 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sat, 9 Mar 2013 18:14:53 +0100 Subject: [PATCH 07/31] Added info link for apple restriction feature. --- app/views/home/_apple_bar.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/home/_apple_bar.html.haml b/app/views/home/_apple_bar.html.haml index 6cbdd875..c7c062ba 100644 --- a/app/views/home/_apple_bar.html.haml +++ b/app/views/home/_apple_bar.html.haml @@ -7,4 +7,5 @@ Deine aktueller Äpfelpunktestand: #{apple_bar.apples} Konkret: Pro #{number_to_currency(apple_bar.mean_order_amount_per_job, :precision => 0 )} Bestellsumme solltest Du eine Aufgabe machen! - if FoodsoftConfig[:stop_ordering_under].present? %strong Achtung, - hast Du weniger als #{FoodsoftConfig[:stop_ordering_under]} Äpfel, darfst Du nicht mehr bestellen! \ No newline at end of file + hast Du weniger als #{FoodsoftConfig[:stop_ordering_under]} Äpfel, darfst Du nicht mehr bestellen! + = link_to 'Mehr Informationen', 'https://github.com/bennibu/foodsoft/wiki/%C3%84pfel-u.-Birnen', target: '_blank' \ No newline at end of file From b0e12d177ed9ce3eac6069357299a46e0471072d Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 10 Mar 2013 19:22:26 +0100 Subject: [PATCH 08/31] Fixed editing an order and take care of group_orders. --- app/models/order.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 6e48756c..67a04443 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -19,8 +19,7 @@ class Order < ActiveRecord::Base validate :starts_before_ends, :include_articles # Callbacks - after_update :update_price_of_group_orders - after_save :save_order_articles + after_save :save_order_articles, :update_price_of_group_orders # Finders scope :open, where(state: 'open').order('ends DESC') @@ -215,7 +214,14 @@ class Order < ActiveRecord::Base end def save_order_articles - self.articles = Article.find(article_ids) + self.articles = Article.find(article_ids) # This doesn't deletes the group_order_articles, belonging to order_articles, + # see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many + + # Ensure to delete also the group_order_articles, belonging to order_articles + # This case is relevant, when removing articles from a running order + goa_ids = GroupOrderArticle.where(group_order_id: group_order_ids).includes(:order_article). + select { |goa| goa.order_article.nil? }.map(&:id) + GroupOrderArticle.delete_all(id: goa_ids) unless goa_ids.empty? end private From c18fb2011567f99958ca70ceafc215c6f42a40bc Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 10 Mar 2013 19:39:59 +0100 Subject: [PATCH 09/31] Ensure to get also deleted entries in belongs_to assoc. --- app/models/article.rb | 2 +- app/models/article_price.rb | 2 +- app/models/delivery.rb | 2 +- app/models/financial_transaction.rb | 2 +- app/models/group_order.rb | 2 +- app/models/invoice.rb | 2 +- app/models/order.rb | 2 +- app/models/order_article.rb | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 09f17fa4..32554e84 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -7,7 +7,7 @@ class Article < ActiveRecord::Base localize_input_of :price, :tax, :deposit # Associations - belongs_to :supplier + belongs_to :supplier, :with_deleted => true belongs_to :article_category has_many :article_prices, :order => "created_at DESC" diff --git a/app/models/article_price.rb b/app/models/article_price.rb index e946fc92..686b891c 100644 --- a/app/models/article_price.rb +++ b/app/models/article_price.rb @@ -1,6 +1,6 @@ class ArticlePrice < ActiveRecord::Base - belongs_to :article + belongs_to :article, :with_deleted => true has_many :order_articles validates_presence_of :price, :tax, :deposit, :unit_quantity diff --git a/app/models/delivery.rb b/app/models/delivery.rb index 3add6fdf..b9c04616 100644 --- a/app/models/delivery.rb +++ b/app/models/delivery.rb @@ -1,6 +1,6 @@ class Delivery < ActiveRecord::Base - belongs_to :supplier + belongs_to :supplier, :with_deleted => true has_one :invoice has_many :stock_changes, :dependent => :destroy diff --git a/app/models/financial_transaction.rb b/app/models/financial_transaction.rb index 354a3d2a..bdd7e48a 100644 --- a/app/models/financial_transaction.rb +++ b/app/models/financial_transaction.rb @@ -1,7 +1,7 @@ # financial transactions are the foodcoop internal financial transactions # only ordergroups have an account balance and are happy to transfer money class FinancialTransaction < ActiveRecord::Base - belongs_to :ordergroup + belongs_to :ordergroup, :with_deleted => true belongs_to :user validates_presence_of :amount, :note, :user_id, :ordergroup_id diff --git a/app/models/group_order.rb b/app/models/group_order.rb index 9685d3bb..96dae5b8 100644 --- a/app/models/group_order.rb +++ b/app/models/group_order.rb @@ -4,7 +4,7 @@ class GroupOrder < ActiveRecord::Base attr_accessor :group_order_articles_attributes belongs_to :order - belongs_to :ordergroup + belongs_to :ordergroup, :with_deleted => true has_many :group_order_articles, :dependent => :destroy has_many :order_articles, :through => :group_order_articles belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by_user_id" diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 0feb3ede..a9f1d9ca 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -1,6 +1,6 @@ class Invoice < ActiveRecord::Base - belongs_to :supplier + belongs_to :supplier, :with_deleted => true belongs_to :delivery belongs_to :order diff --git a/app/models/order.rb b/app/models/order.rb index 67a04443..4472ddd9 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -10,7 +10,7 @@ class Order < ActiveRecord::Base has_one :invoice has_many :comments, :class_name => "OrderComment", :order => "created_at" has_many :stock_changes - belongs_to :supplier + belongs_to :supplier, :with_deleted => true belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_user_id' belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id' diff --git a/app/models/order_article.rb b/app/models/order_article.rb index a6b13a27..dbceb683 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -4,7 +4,7 @@ class OrderArticle < ActiveRecord::Base attr_reader :update_current_price belongs_to :order - belongs_to :article + belongs_to :article, :with_deleted => true belongs_to :article_price has_many :group_order_articles, :dependent => :destroy From 40d9195eac9ac5552b7176c6cd8af93a9816913b Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Tue, 12 Mar 2013 11:26:14 +0100 Subject: [PATCH 10/31] Fixed broken group_orders after editing order. Caution, when using the model.association = models operator, the after save callbacks are not triggerd! See Order#save_order_articles --- app/models/group_order.rb | 34 ++++++++++++---------------------- app/models/order.rb | 24 +++++++++++++++++------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/app/models/group_order.rb b/app/models/group_order.rb index 96dae5b8..04e69de7 100644 --- a/app/models/group_order.rb +++ b/app/models/group_order.rb @@ -22,35 +22,25 @@ class GroupOrder < ActiveRecord::Base data = {} data[:available_funds] = ordergroup.get_available_funds(self) - unless new_record? - # Group has already ordered, so get the results... - goas = {} - group_order_articles.all.each do |goa| - goas[goa.order_article_id] = { - :quantity => goa.quantity, - :tolerance => goa.tolerance, - :quantity_result => goa.result(:quantity), - :tolerance_result => goa.result(:tolerance), - :total_price => goa.total_price - } - end - end - # load prices and other stuff.... data[:order_articles] = {} - #order.order_articles.each do |order_article| order.articles_grouped_by_category.each do |article_category, order_articles| order_articles.each do |order_article| + + # Get the result of last time ordering, if possible + goa = group_order_articles.detect { |goa| goa.order_article_id == order_article.id } + + # Build hash with relevant data data[:order_articles][order_article.id] = { :price => order_article.article.fc_price, :unit => order_article.article.unit_quantity, - :quantity => (new_record? ? 0 : goas[order_article.id][:quantity]), - :others_quantity => order_article.quantity - (new_record? ? 0 : goas[order_article.id][:quantity]), - :used_quantity => (new_record? ? 0 : goas[order_article.id][:quantity_result]), - :tolerance => (new_record? ? 0 : goas[order_article.id][:tolerance]), - :others_tolerance => order_article.tolerance - (new_record? ? 0 : goas[order_article.id][:tolerance]), - :used_tolerance => (new_record? ? 0 : goas[order_article.id][:tolerance_result]), - :total_price => (new_record? ? 0 : goas[order_article.id][:total_price]), + :quantity => (goa ? goa.quantity : 0), + :others_quantity => order_article.quantity - (goa ? goa.quantity : 0), + :used_quantity => (goa ? goa.result(:quantity) : 0), + :tolerance => (goa ? goa.result(:tolerance) : 0), + :others_tolerance => order_article.tolerance - (goa ? goa.result(:tolerance) : 0), + :used_tolerance => (goa ? goa.result(:tolerance) : 0), + :total_price => (goa ? goa.total_price : 0), :missing_units => order_article.missing_units, :quantity_available => (order.stockit? ? order_article.article.quantity_available : 0) } diff --git a/app/models/order.rb b/app/models/order.rb index 4472ddd9..5afc166a 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -214,14 +214,24 @@ class Order < ActiveRecord::Base end def save_order_articles - self.articles = Article.find(article_ids) # This doesn't deletes the group_order_articles, belonging to order_articles, - # see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many + #self.articles = Article.find(article_ids) # This doesn't deletes the group_order_articles, belonging to order_articles, + # # see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many + # + ## Ensure to delete also the group_order_articles, belonging to order_articles + ## This case is relevant, when removing articles from a running order + #goa_ids = GroupOrderArticle.where(group_order_id: group_order_ids).includes(:order_article). + # select { |goa| goa.order_article.nil? }.map(&:id) + #GroupOrderArticle.delete_all(id: goa_ids) unless goa_ids.empty? - # Ensure to delete also the group_order_articles, belonging to order_articles - # This case is relevant, when removing articles from a running order - goa_ids = GroupOrderArticle.where(group_order_id: group_order_ids).includes(:order_article). - select { |goa| goa.order_article.nil? }.map(&:id) - GroupOrderArticle.delete_all(id: goa_ids) unless goa_ids.empty? + + # fetch selected articles + articles_list = Article.find(article_ids) + # create new order_articles + (articles_list - articles).each { |article| order_articles.create(:article => article) } + # delete old order_articles + articles.reject { |article| articles_list.include?(article) }.each do |article| + order_articles.detect { |order_article| order_article.article_id == article.id }.destroy + end end private From 6196bdae410871e4b86762f8b2ee19c410ceb6b5 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Tue, 12 Mar 2013 12:34:05 +0100 Subject: [PATCH 11/31] Added some eager loading for balancing new. --- app/controllers/finance/balancing_controller.rb | 6 ++++-- app/views/finance/balancing/_group_order_articles.html.haml | 2 +- app/views/finance/balancing/new.html.haml | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 1b55d177..8f40a017 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -21,8 +21,10 @@ class Finance::BalancingController < Finance::BaseController sort = "id" end - @articles = @order.order_articles.ordered.includes(:article).order(sort) - + @articles = @order.order_articles.ordered.includes(:order, :article, :article_price, + group_order_articles: {group_order: :ordergroup}).order(sort) + + if params[:sort] == "order_number" @articles = @articles.to_a.sort { |a,b| a.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> b.article.order_number.gsub(/[^[:digit:]]/, "").to_i } elsif params[:sort] == "order_number_reverse" diff --git a/app/views/finance/balancing/_group_order_articles.html.haml b/app/views/finance/balancing/_group_order_articles.html.haml index 3cc34dfd..a4a6bb7a 100644 --- a/app/views/finance/balancing/_group_order_articles.html.haml +++ b/app/views/finance/balancing/_group_order_articles.html.haml @@ -10,7 +10,7 @@ = link_to 'Gruppe hinzufügen', new_finance_group_order_article_path(order_article_id: order_article.id), remote: true, class: 'btn btn-mini' %tbody - - for group_order_article in order_article.group_order_articles.ordered.all(:include => [:group_order]) + - for group_order_article in order_article.group_order_articles.select { |goa| goa.result > 0 } %tr[group_order_article] %td %td{:style=>"width:50%"} diff --git a/app/views/finance/balancing/new.html.haml b/app/views/finance/balancing/new.html.haml index 50cb3d4c..e151ccd0 100644 --- a/app/views/finance/balancing/new.html.haml +++ b/app/views/finance/balancing/new.html.haml @@ -20,7 +20,7 @@ .well.well-small %h3 Kommentare - #comments= render :partial => 'shared/comments', locals: {comments: @order.comments} + #comments= render :partial => 'shared/comments', locals: {comments: @order.comments.includes(:user)} - content_for :actionbar do .btn-group From c4376f35bf5e3d0215ba9ec9f93c949b4c1152e4 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Tue, 12 Mar 2013 12:50:56 +0100 Subject: [PATCH 12/31] Removed article from includes in as it does not work with acts_as_paranoid. See also https://github.com/goncalossilva/rails3_acts_as_paranoid/issues/62. Better we remove acts_as_paranoid and filter manually? --- app/controllers/finance/balancing_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 8f40a017..18031dbd 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -21,10 +21,9 @@ class Finance::BalancingController < Finance::BaseController sort = "id" end - @articles = @order.order_articles.ordered.includes(:order, :article, :article_price, + @articles = @order.order_articles.ordered.includes(:order, :article_price, group_order_articles: {group_order: :ordergroup}).order(sort) - if params[:sort] == "order_number" @articles = @articles.to_a.sort { |a,b| a.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> b.article.order_number.gsub(/[^[:digit:]]/, "").to_i } elsif params[:sort] == "order_number_reverse" From 0d3564492bbccc5a455f666e4cff033dda707860 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Tue, 12 Mar 2013 18:54:51 +0100 Subject: [PATCH 13/31] Fixed bug in sorting articles in balancing view. --- .../finance/balancing_controller.rb | 31 +++++++++---------- app/models/order_article.rb | 11 +++++++ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 18031dbd..71ce19ed 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -10,25 +10,22 @@ class Finance::BalancingController < Finance::BaseController flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed? @comments = @order.comments - if params['sort'] - sort = case params['sort'] - when "name" then "articles.name" - when "order_number" then "articles.order_number" - when "name_reverse" then "articles.name DESC" - when "order_number_reverse" then "articles.order_number DESC" - end - else - sort = "id" - end - @articles = @order.order_articles.ordered.includes(:order, :article_price, - group_order_articles: {group_order: :ordergroup}).order(sort) + group_order_articles: {group_order: :ordergroup}) - if params[:sort] == "order_number" - @articles = @articles.to_a.sort { |a,b| a.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> b.article.order_number.gsub(/[^[:digit:]]/, "").to_i } - elsif params[:sort] == "order_number_reverse" - @articles = @articles.to_a.sort { |a,b| b.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> a.article.order_number.gsub(/[^[:digit:]]/, "").to_i } - end + sort_param = params['sort'] || 'name' + @articles = case sort_param + when 'name' then + OrderArticle.sort_by_name(@articles) + when 'name_reverse' then + OrderArticle.sort_by_name(@articles).reverse + when 'order_number' then + OrderArticle.sort_by_order_number(@articles) + when 'order_number_reverse' then + OrderArticle.sort_by_order_number(@articles).reverse + else + @articles + end render layout: false if request.xhr? end diff --git a/app/models/order_article.rb b/app/models/order_article.rb index dbceb683..b68bfe82 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -17,6 +17,17 @@ class OrderArticle < ActiveRecord::Base before_create :init_from_balancing after_destroy :update_ordergroup_prices + def self.sort_by_name(order_articles) + order_articles.sort { |a,b| a.article.name <=> b.article.name } + end + + def self.sort_by_order_number(order_articles) + order_articles.sort do |a,b| + a.article.order_number.to_s.gsub(/[^[:digit:]]/, "").to_i <=> + b.article.order_number.to_s.gsub(/[^[:digit:]]/, "").to_i + end + end + # This method returns either the ArticlePrice or the Article # The first will be set, when the the order is finished def price From 8bafb3f4b2de7ea6506d112e11c5f4bd65855948 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Tue, 12 Mar 2013 19:08:18 +0100 Subject: [PATCH 14/31] Show supplier name for articles in stockit order. --- app/views/group_orders/_form.html.haml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/views/group_orders/_form.html.haml b/app/views/group_orders/_form.html.haml index b1103462..b040354e 100644 --- a/app/views/group_orders/_form.html.haml +++ b/app/views/group_orders/_form.html.haml @@ -45,6 +45,8 @@ %thead %tr %th Name + - if @order.stockit? + %th{style: 'width:120px'} Lieferant %th{style: "width:13px;"} %th{style: "width:4.5em;"} Preis %th{style: "width:4.5em;"} Einheit @@ -66,6 +68,8 @@ - order_articles.each do |order_article| %tr{class: "#{cycle('even', 'odd', name: 'articles')} order-article", valign: "top"} %td.name= order_article.article.name + - if @order.stockit? + %td= truncate order_article.article.supplier.name, length: 15 %td= h order_article.article.origin %td= number_to_currency(@ordering_data[:order_articles][order_article.id][:price]) %td= order_article.article.unit From 32083213198072e55e2291acb580b90467c40e7d Mon Sep 17 00:00:00 2001 From: Julius Date: Thu, 14 Mar 2013 21:55:10 +0100 Subject: [PATCH 15/31] Fix stockit increase formula for present behavior --- app/assets/javascripts/ordering.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/ordering.js b/app/assets/javascripts/ordering.js index ac61155a..a75d0541 100644 --- a/app/assets/javascripts/ordering.js +++ b/app/assets/javascripts/ordering.js @@ -49,7 +49,7 @@ function addData(orderArticleId, itemPrice, itemUnit, itemSubtotal, itemQuantity function increaseQuantity(item) { var value = Number($('#q_' + item).val()) + 1; - if (!isStockit || (value <= (quantityAvailable[item] - quantityOthers[item]))) { + if (!isStockit || (value <= (quantityAvailable[item] + itemsAllocated[item]))) { update(item, value, $('#t_' + item).val()); } } From 396e2203699e6717d540ec68f27411a95b1b72d5 Mon Sep 17 00:00:00 2001 From: Julius Date: Thu, 14 Mar 2013 22:30:22 +0100 Subject: [PATCH 16/31] Prevent article names from being truncated in StockTaking form --- app/views/stock_takings/_stock_change.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/stock_takings/_stock_change.html.haml b/app/views/stock_takings/_stock_change.html.haml index 0c3d766e..616be369 100644 --- a/app/views/stock_takings/_stock_change.html.haml +++ b/app/views/stock_takings/_stock_change.html.haml @@ -3,5 +3,5 @@ = form.hidden_field :stock_article_id = "Menge (#{stock_change.stock_article.quantity_available})" = form.text_field :quantity, :size => 5, :autocomplete => 'off' - %b=h truncate(stock_change.stock_article.name) + %b= stock_change.stock_article.name = "(#{number_to_currency(stock_change.stock_article.price)} / #{stock_change.stock_article.unit})" From 6aa0e0b7365afcb5527c887ba22e7689c702a39e Mon Sep 17 00:00:00 2001 From: Julius Date: Fri, 15 Mar 2013 08:50:55 +0100 Subject: [PATCH 17/31] Rename and comment new functions for fixing stock ordering --- app/models/article.rb | 5 +++-- app/models/order.rb | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 22d9a322..1c4617ac 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -48,8 +48,9 @@ class Article < ActiveRecord::Base order_article ? order_article.order : nil end memoize :in_open_order - - def ordered?(order) + + # Returns true if the article has been ordered in the given order at least once + def ordered_in_order?(order) order.order_articles.where(article_id: id).where('quantity > 0').one? end diff --git a/app/models/order.rb b/app/models/order.rb index 07c74878..56eb9cab 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -38,9 +38,11 @@ class Order < ActiveRecord::Base def articles_for_ordering if stockit? + # make sure to include those articles which are no longer available + # but which have already been ordered in this stock order StockArticle.available.all(:include => :article_category, :order => 'article_categories.name, articles.name').reject{ |a| - a.quantity_available <= 0 and not a.ordered?(self) + a.quantity_available <= 0 and not a.ordered_in_order?(self) }.group_by { |a| a.article_category.name } else supplier.articles.available.all.group_by { |a| a.article_category.name } From 07581b7ecf8846fe5c8dc4f496d498c1ae3727d4 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sat, 16 Mar 2013 17:53:24 +0100 Subject: [PATCH 18/31] Removed acts_as_paranoid. Implemented own version. --- Gemfile | 1 - Gemfile.lock | 3 -- .../admin/ordergroups_controller.rb | 4 +-- app/controllers/articles_controller.rb | 35 ++++++++++--------- .../finance/ordergroups_controller.rb | 2 +- .../foodcoop/ordergroups_controller.rb | 2 +- app/controllers/stockit_controller.rb | 4 +-- app/controllers/suppliers_controller.rb | 4 +-- app/models/article.rb | 13 +++++-- app/models/article_price.rb | 2 +- app/models/delivery.rb | 2 +- app/models/financial_transaction.rb | 2 +- app/models/group.rb | 20 +++++++++-- app/models/group_order.rb | 2 +- app/models/invoice.rb | 2 +- app/models/order.rb | 2 +- app/models/order_article.rb | 2 +- app/models/ordergroup.rb | 3 +- app/models/stock_article.rb | 10 ++++-- app/models/stock_change.rb | 2 +- app/models/supplier.rb | 21 ++++++++--- app/views/articles/index.haml | 4 +-- app/views/messages/new.haml | 2 +- app/views/orders/index.html.haml | 2 +- app/views/suppliers/index.haml | 4 +-- 25 files changed, 93 insertions(+), 57 deletions(-) diff --git a/Gemfile b/Gemfile index 42a9cc09..f311f384 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,6 @@ gem 'haml-rails' gem 'kaminari' gem 'client_side_validations' gem 'simple_form' -gem 'rails3_acts_as_paranoid', "~>0.2.0" gem 'inherited_resources' gem 'localize_input', :git => "git://github.com/bennibu/localize_input.git" gem 'wikicloth' diff --git a/Gemfile.lock b/Gemfile.lock index b44f286d..aabdad24 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -143,8 +143,6 @@ GEM activesupport (= 3.2.11) bundler (~> 1.0) railties (= 3.2.11) - rails3_acts_as_paranoid (0.2.4) - activerecord (~> 3.2) railties (3.2.11) actionpack (= 3.2.11) activesupport (= 3.2.11) @@ -240,7 +238,6 @@ DEPENDENCIES mysql2 prawn rails (~> 3.2.9) - rails3_acts_as_paranoid (~> 0.2.0) resque ruby-prof sass-rails (~> 3.2.3) diff --git a/app/controllers/admin/ordergroups_controller.rb b/app/controllers/admin/ordergroups_controller.rb index 828d91a6..c019ee55 100644 --- a/app/controllers/admin/ordergroups_controller.rb +++ b/app/controllers/admin/ordergroups_controller.rb @@ -3,7 +3,7 @@ class Admin::OrdergroupsController < Admin::BaseController inherit_resources def index - @ordergroups = Ordergroup.order('name ASC') + @ordergroups = Ordergroup.undeleted.order('name ASC') # if somebody uses the search field: unless params[:query].blank? @@ -15,7 +15,7 @@ class Admin::OrdergroupsController < Admin::BaseController def destroy @ordergroup = Ordergroup.find(params[:id]) - @ordergroup.destroy + @ordergroup.mark_as_deleted redirect_to admin_ordergroups_url, :notice => "Bestellgruppe wurde gelöscht" rescue => error redirect_to admin_ordergroups_url, :alert => "Bestellgruppe konnte nicht gelöscht werden: #{error}" diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 35bd36db..a9af168e 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -20,7 +20,7 @@ class ArticlesController < ApplicationController sort = "article_categories.name, articles.name" end - @articles = Article.where(supplier_id: @supplier, :type => nil).includes(:article_category).order(sort) + @articles = Article.undeleted.where(supplier_id: @supplier, :type => nil).includes(:article_category).order(sort) @articles = @articles.where('articles.name LIKE ?', "%#{params[:query]}%") unless params[:query].nil? @articles = @articles.page(params[:page]).per(@per_page) @@ -64,13 +64,13 @@ class ArticlesController < ApplicationController # Deletes article from database. send error msg, if article is used in a current order def destroy @article = Article.find(params[:id]) - @article.destroy unless @order = @article.in_open_order # If article is in an active Order, the Order will be returned + @article.mark_as_deleted unless @order = @article.in_open_order # If article is in an active Order, the Order will be returned render :layout => false end # Renders a form for editing all articles from a supplier def edit_all - @articles = @supplier.articles + @articles = @supplier.articles.undeleted end # Updates all article of specific supplier @@ -114,23 +114,24 @@ class ArticlesController < ApplicationController def update_selected raise 'Du hast keine Artikel ausgewählt' if params[:selected_articles].nil? articles = Article.find(params[:selected_articles]) - - case params[:selected_action] - when 'destroy' - articles.each {|a| a.destroy } - flash[:notice] = 'Alle gewählten Artikel wurden gelöscht' - when 'setNotAvailable' - articles.each {|a| a.update_attribute(:availability, false) } - flash[:notice] = 'Alle gewählten Artikel wurden auf "nicht verfügbar" gesetzt' - when 'setAvailable' - articles.each {|a| a.update_attribute(:availability, true) } - flash[:notice] = 'Alle gewählten Artikel wurden auf "verfügbar" gesetzt' - else - flash[:alert] = 'Keine Aktion ausgewählt!' + Article.transaction do + case params[:selected_action] + when 'destroy' + articles.each(&:mark_as_deleted) + flash[:notice] = 'Alle gewählten Artikel wurden gelöscht' + when 'setNotAvailable' + articles.each {|a| a.update_attribute(:availability, false) } + flash[:notice] = 'Alle gewählten Artikel wurden auf "nicht verfügbar" gesetzt' + when 'setAvailable' + articles.each {|a| a.update_attribute(:availability, true) } + flash[:notice] = 'Alle gewählten Artikel wurden auf "verfügbar" gesetzt' + else + flash[:alert] = 'Keine Aktion ausgewählt!' + end end # action succeded redirect_to supplier_articles_url(@supplier, :per_page => params[:per_page]) - + rescue => error redirect_to supplier_articles_url(@supplier, :per_page => params[:per_page]), :alert => "Ein Fehler ist aufgetreten: #{error}" diff --git a/app/controllers/finance/ordergroups_controller.rb b/app/controllers/finance/ordergroups_controller.rb index 3b618e37..d4daeff6 100644 --- a/app/controllers/finance/ordergroups_controller.rb +++ b/app/controllers/finance/ordergroups_controller.rb @@ -12,7 +12,7 @@ class Finance::OrdergroupsController < Finance::BaseController sort = "name" end - @ordergroups = Ordergroup.order(sort) + @ordergroups = Ordergroup.undeleted.order(sort) @ordergroups = @ordergroups.where('name LIKE ?', "%#{params[:query]}%") unless params[:query].nil? @ordergroups = @ordergroups.page(params[:page]).per(@per_page) diff --git a/app/controllers/foodcoop/ordergroups_controller.rb b/app/controllers/foodcoop/ordergroups_controller.rb index 0975b9a5..5391b798 100644 --- a/app/controllers/foodcoop/ordergroups_controller.rb +++ b/app/controllers/foodcoop/ordergroups_controller.rb @@ -1,7 +1,7 @@ class Foodcoop::OrdergroupsController < ApplicationController def index - @ordergroups = Ordergroup.order('name DESC') + @ordergroups = Ordergroup.undeleted.order('name DESC') unless params[:name].blank? # Search by name @ordergroups = @ordergroups.where('name LIKE ?', "%#{params[:name]}%") diff --git a/app/controllers/stockit_controller.rb b/app/controllers/stockit_controller.rb index 2a232a31..03befe63 100644 --- a/app/controllers/stockit_controller.rb +++ b/app/controllers/stockit_controller.rb @@ -1,7 +1,7 @@ class StockitController < ApplicationController def index - @stock_articles = StockArticle.includes(:supplier, :article_category). + @stock_articles = StockArticle.undeleted.includes(:supplier, :article_category). order('suppliers.name, article_categories.name, articles.name') end @@ -33,7 +33,7 @@ class StockitController < ApplicationController def destroy @article = StockArticle.find(params[:id]) - @article.destroy + @article.mark_as_deleted render :layout => false rescue => error render :partial => "destroy_fail", :layout => false, diff --git a/app/controllers/suppliers_controller.rb b/app/controllers/suppliers_controller.rb index 5851c714..5a14e184 100644 --- a/app/controllers/suppliers_controller.rb +++ b/app/controllers/suppliers_controller.rb @@ -4,7 +4,7 @@ class SuppliersController < ApplicationController helper :deliveries def index - @suppliers = Supplier.order(:name) + @suppliers = Supplier.undeleted.order(:name) @deliveries = Delivery.recent end @@ -50,7 +50,7 @@ class SuppliersController < ApplicationController def destroy @supplier = Supplier.find(params[:id]) - @supplier.destroy + @supplier.mark_as_deleted flash[:notice] = "Lieferant wurde gelöscht" redirect_to suppliers_path rescue => e diff --git a/app/models/article.rb b/app/models/article.rb index 32554e84..852bed32 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -1,16 +1,16 @@ # encoding: utf-8 class Article < ActiveRecord::Base - acts_as_paranoid # Avoid deleting the article for consistency of order-results extend ActiveSupport::Memoizable # Ability to cache method results. Use memoize :expensive_method # Replace numeric seperator with database format localize_input_of :price, :tax, :deposit # Associations - belongs_to :supplier, :with_deleted => true + belongs_to :supplier belongs_to :article_category has_many :article_prices, :order => "created_at DESC" + scope :undeleted, -> { where(deleted_at: nil) } scope :available, :conditions => {:availability => true} scope :not_in_stock, :conditions => {:type => nil} @@ -136,6 +136,15 @@ class Article < ActiveRecord::Base end end + def deleted? + deleted_at.present? + end + + def mark_as_deleted + check_article_in_use + update_column :deleted_at, Time.now + end + protected # Checks if the article is in use before it will deleted diff --git a/app/models/article_price.rb b/app/models/article_price.rb index 686b891c..e946fc92 100644 --- a/app/models/article_price.rb +++ b/app/models/article_price.rb @@ -1,6 +1,6 @@ class ArticlePrice < ActiveRecord::Base - belongs_to :article, :with_deleted => true + belongs_to :article has_many :order_articles validates_presence_of :price, :tax, :deposit, :unit_quantity diff --git a/app/models/delivery.rb b/app/models/delivery.rb index b9c04616..3add6fdf 100644 --- a/app/models/delivery.rb +++ b/app/models/delivery.rb @@ -1,6 +1,6 @@ class Delivery < ActiveRecord::Base - belongs_to :supplier, :with_deleted => true + belongs_to :supplier has_one :invoice has_many :stock_changes, :dependent => :destroy diff --git a/app/models/financial_transaction.rb b/app/models/financial_transaction.rb index bdd7e48a..354a3d2a 100644 --- a/app/models/financial_transaction.rb +++ b/app/models/financial_transaction.rb @@ -1,7 +1,7 @@ # financial transactions are the foodcoop internal financial transactions # only ordergroups have an account balance and are happy to transfer money class FinancialTransaction < ActiveRecord::Base - belongs_to :ordergroup, :with_deleted => true + belongs_to :ordergroup belongs_to :user validates_presence_of :amount, :note, :user_id, :ordergroup_id diff --git a/app/models/group.rb b/app/models/group.rb index 68cb015c..092c0119 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,13 +1,15 @@ # Groups organize the User. # A Member gets the roles from the Group class Group < ActiveRecord::Base - has_many :memberships, :dependent => :destroy + has_many :memberships has_many :users, :through => :memberships validates :name, :presence => true, :length => {:in => 1..25} attr_reader :user_tokens - + + scope :undeleted, -> { where(deleted_at: nil) } + # Returns true if the given user if is an member of this group. def member?(user) memberships.find_by_user_id(user.id) @@ -21,7 +23,19 @@ class Group < ActiveRecord::Base def user_tokens=(ids) self.user_ids = ids.split(",") end - + + def deleted? + deleted_at.present? + end + + def mark_as_deleted + # TODO: Checks for participating in not closed orders + transaction do + memberships.destroy_all + # TODO: What should happen to users? + update_column :deleted_at, Time.now + end + end end diff --git a/app/models/group_order.rb b/app/models/group_order.rb index 04e69de7..35bec437 100644 --- a/app/models/group_order.rb +++ b/app/models/group_order.rb @@ -4,7 +4,7 @@ class GroupOrder < ActiveRecord::Base attr_accessor :group_order_articles_attributes belongs_to :order - belongs_to :ordergroup, :with_deleted => true + belongs_to :ordergroup has_many :group_order_articles, :dependent => :destroy has_many :order_articles, :through => :group_order_articles belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by_user_id" diff --git a/app/models/invoice.rb b/app/models/invoice.rb index a9f1d9ca..0feb3ede 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -1,6 +1,6 @@ class Invoice < ActiveRecord::Base - belongs_to :supplier, :with_deleted => true + belongs_to :supplier belongs_to :delivery belongs_to :order diff --git a/app/models/order.rb b/app/models/order.rb index 5afc166a..480df14a 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -10,7 +10,7 @@ class Order < ActiveRecord::Base has_one :invoice has_many :comments, :class_name => "OrderComment", :order => "created_at" has_many :stock_changes - belongs_to :supplier, :with_deleted => true + belongs_to :supplier belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_user_id' belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id' diff --git a/app/models/order_article.rb b/app/models/order_article.rb index b68bfe82..af257f5d 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -4,7 +4,7 @@ class OrderArticle < ActiveRecord::Base attr_reader :update_current_price belongs_to :order - belongs_to :article, :with_deleted => true + belongs_to :article belongs_to :article_price has_many :group_order_articles, :dependent => :destroy diff --git a/app/models/ordergroup.rb b/app/models/ordergroup.rb index dbfe3171..ad1cffde 100644 --- a/app/models/ordergroup.rb +++ b/app/models/ordergroup.rb @@ -8,7 +8,6 @@ class Ordergroup < Group APPLE_MONTH_AGO = 6 # How many month back we will count tasks and orders sum - acts_as_paranoid # Avoid deleting the ordergroup for consistency of order-results serialize :stats has_many :financial_transactions @@ -110,7 +109,7 @@ class Ordergroup < Group # Make sure, the name is uniq, add usefull message if uniq group is already deleted def uniqueness_of_name id = new_record? ? '' : self.id - group = Ordergroup.with_deleted.where('groups.id != ? AND groups.name = ?', id, name).first + group = Ordergroup.where('groups.id != ? AND groups.name = ?', id, name).first if group.present? message = group.deleted? ? :taken_with_deleted : :taken errors.add :name, message diff --git a/app/models/stock_article.rb b/app/models/stock_article.rb index 6050c8c4..21c8bb56 100644 --- a/app/models/stock_article.rb +++ b/app/models/stock_article.rb @@ -1,10 +1,9 @@ # encoding: utf-8 class StockArticle < Article - acts_as_paranoid - + has_many :stock_changes - scope :available, :conditions => "quantity > 0" + scope :available, -> { undeleted.where'quantity > 0' } before_destroy :check_quantity @@ -23,6 +22,11 @@ class StockArticle < Article available.collect { |a| a.quantity * a.gross_price }.sum end + def mark_as_deleted + check_quantity + super + end + protected def check_quantity diff --git a/app/models/stock_change.rb b/app/models/stock_change.rb index 029b92b6..6a7adc75 100644 --- a/app/models/stock_change.rb +++ b/app/models/stock_change.rb @@ -1,7 +1,7 @@ class StockChange < ActiveRecord::Base belongs_to :delivery belongs_to :order - belongs_to :stock_article, with_deleted: true + belongs_to :stock_article validates_presence_of :stock_article_id, :quantity validates_numericality_of :quantity diff --git a/app/models/supplier.rb b/app/models/supplier.rb index 384c5973..557cd4e4 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -1,7 +1,7 @@ +# encoding: utf-8 class Supplier < ActiveRecord::Base - acts_as_paranoid # Avoid deleting the supplier for consistency of order-results - has_many :articles, :dependent => :destroy, :conditions => {:type => nil}, + has_many :articles, :conditions => {:type => nil}, :include => [:article_category], :order => 'article_categories.name, articles.name' has_many :stock_articles, :include => [:article_category], :order => 'article_categories.name, articles.name' has_many :orders @@ -20,13 +20,15 @@ class Supplier < ActiveRecord::Base validates_length_of :address, :in => 8..50 validate :uniqueness_of_name + scope :undeleted, -> { where(deleted_at: nil) } + # sync all articles with the external database # returns an array with articles(and prices), which should be updated (to use in a form) # also returns an array with outlisted_articles, which should be deleted def sync_all updated_articles = Array.new outlisted_articles = Array.new - for article in articles + for article in articles.undeleted # try to find the associated shared_article shared_article = article.shared_article @@ -65,12 +67,23 @@ class Supplier < ActiveRecord::Base return [updated_articles, outlisted_articles] end + def deleted? + deleted_at.present? + end + + def mark_as_deleted + transaction do + update_column :deleted_at, Time.now + articles.each(&:mark_as_deleted) + end + end + protected # Make sure, the name is uniq, add usefull message if uniq group is already deleted def uniqueness_of_name id = new_record? ? '' : self.id - supplier = Supplier.with_deleted.where('suppliers.id != ? AND suppliers.name = ?', id, name).first + supplier = Supplier.where('suppliers.id != ? AND suppliers.name = ?', id, name).first if supplier.present? message = supplier.deleted? ? :taken_with_deleted : :taken errors.add :name, message diff --git a/app/views/articles/index.haml b/app/views/articles/index.haml index be976bd5..5c8946ee 100644 --- a/app/views/articles/index.haml +++ b/app/views/articles/index.haml @@ -1,4 +1,4 @@ -- title "Artikel von #{@supplier.name} (#{@supplier.articles.count})" +- title "Artikel von #{@supplier.name} (#{@supplier.articles.undeleted.count})" .well.well-small .btn-toolbar @@ -28,7 +28,7 @@ Lieferant wechseln .. %span.caret %ul.dropdown-menu - - Supplier.where('id != ?', @supplier.id).order('name ASC').each do |supplier| + - Supplier.undeleted.where('id != ?', @supplier.id).order('suppliers.name ASC').each do |supplier| %li= link_to supplier.name, supplier_articles_path(supplier), tabindex: -1 - unless @supplier.shared_supplier.nil? diff --git a/app/views/messages/new.haml b/app/views/messages/new.haml index 965bf7a5..36f70970 100644 --- a/app/views/messages/new.haml +++ b/app/views/messages/new.haml @@ -41,7 +41,7 @@ #recipients = f.input :recipient_tokens, :input_html => { 'data-pre' => User.find_all_by_id(@message.recipients_ids).map { |u| u.token_attributes }.to_json } - = f.input :group_id, :as => :select, :collection => Group.order('type DESC, name ASC').all.reject { |g| g.memberships.empty? } + = f.input :group_id, :as => :select, :collection => Group.undeleted.order('type DESC, name ASC').all.reject { |g| g.memberships.empty? } = f.input :private = f.input :subject, input_html: {class: 'input-xxlarge'} = f.input :body, input_html: {class: 'input-xxlarge'} diff --git a/app/views/orders/index.html.haml b/app/views/orders/index.html.haml index 1ebe04f0..4180c96d 100644 --- a/app/views/orders/index.html.haml +++ b/app/views/orders/index.html.haml @@ -6,7 +6,7 @@ Neue Bestellung anlegen %span.caret %ul.dropdown-menu - - Supplier.all.each do |supplier| + - Supplier.undeleted.order('suppliers.name ASC').each do |supplier| %li= link_to supplier.name, new_order_path(supplier_id: supplier.id), tabindex: -1 .well diff --git a/app/views/suppliers/index.haml b/app/views/suppliers/index.haml index 4697f573..bb9a3e0f 100644 --- a/app/views/suppliers/index.haml +++ b/app/views/suppliers/index.haml @@ -18,8 +18,8 @@ %td= link_to h(supplier.name) , supplier %td= supplier.phone %td= supplier.customer_number - %td= link_to "Artikel (#{supplier.articles.count})", supplier_articles_path(supplier) - %td= link_to "im Lager (#{supplier.stock_articles.count})", stock_articles_path + %td= link_to "Artikel (#{supplier.articles.undeleted.count})", supplier_articles_path(supplier) + %td= link_to "im Lager (#{supplier.stock_articles.undeleted.count})", stock_articles_path %td= link_to "Lieferungen (#{supplier.deliveries.count})", supplier_deliveries_path(supplier) %td = link_to "Bearbeiten", edit_supplier_path(supplier), class: 'btn btn-mini' From 9cc98b4662235293c1aaa5ae6168397a4a5849f8 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 17 Mar 2013 15:12:14 +0100 Subject: [PATCH 19/31] Added some more eager loading for balancing view. --- .../finance/balancing_controller.rb | 2 +- app/models/order.rb | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 71ce19ed..c6e1b108 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -10,7 +10,7 @@ class Finance::BalancingController < Finance::BaseController flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed? @comments = @order.comments - @articles = @order.order_articles.ordered.includes(:order, :article_price, + @articles = @order.order_articles.ordered.includes(:article, :article_price, group_order_articles: {group_order: :ordergroup}) sort_param = params['sort'] || 'name' diff --git a/app/models/order.rb b/app/models/order.rb index 480df14a..7cc5c4bd 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -113,25 +113,25 @@ class Order < ActiveRecord::Base def sum(type = :gross) total = 0 if type == :net || type == :gross || type == :fc - for oa in order_articles.ordered.all(:include => [:article,:article_price]) + for oa in order_articles.ordered.includes(:article, :article_price) quantity = oa.units_to_order * oa.price.unit_quantity case type - when :net - total += quantity * oa.price.price - when :gross - total += quantity * oa.price.gross_price - when :fc - total += quantity * oa.price.fc_price + when :net + total += quantity * oa.price.price + when :gross + total += quantity * oa.price.gross_price + when :fc + total += quantity * oa.price.fc_price end end elsif type == :groups || type == :groups_without_markup - for go in group_orders.all(:include => :group_order_articles) - for goa in go.group_order_articles.all(:include => [:order_article]) + for go in group_orders.includes(group_order_articles: {order_article: [:article, :article_price]}) + for goa in go.group_order_articles case type - when :groups - total += goa.result * goa.order_article.price.fc_price - when :groups_without_markup - total += goa.result * goa.order_article.price.gross_price + when :groups + total += goa.result * goa.order_article.price.fc_price + when :groups_without_markup + total += goa.result * goa.order_article.price.gross_price end end end From c05b3e0e192ca0e50e29462d2cf619a98d122c87 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 17 Mar 2013 15:47:50 +0100 Subject: [PATCH 20/31] Balancing: Do not update oder summary automaticly when changing group orders. --- app/controllers/finance/balancing_controller.rb | 4 ++++ app/views/finance/balancing/_summary.haml | 6 +++++- app/views/finance/balancing/update_summary.js.haml | 1 + app/views/finance/group_order_articles/update.js.haml | 2 +- config/routes.rb | 1 + 5 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 app/views/finance/balancing/update_summary.js.haml diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index c6e1b108..df5eb22a 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -30,6 +30,10 @@ class Finance::BalancingController < Finance::BaseController render layout: false if request.xhr? end + def update_summary + @order = Order.find(params[:id]) + end + def edit_note @order = Order.find(params[:id]) render :layout => false diff --git a/app/views/finance/balancing/_summary.haml b/app/views/finance/balancing/_summary.haml index b43b3e58..a3ce80a0 100644 --- a/app/views/finance/balancing/_summary.haml +++ b/app/views/finance/balancing/_summary.haml @@ -24,4 +24,8 @@ %td FC Gewinn %small mit Aufschlag: - %td#order_profit.numeric= number_to_currency(order.profit) \ No newline at end of file + %td#order_profit.numeric= number_to_currency(order.profit) +#summaryChangedWarning.alert(style="display:none;") + %strong Daten wurden verändert! + %br/ + = link_to 'Zusammenfassung neu laden', update_summary_finance_order_path(order), remote: true \ No newline at end of file diff --git a/app/views/finance/balancing/update_summary.js.haml b/app/views/finance/balancing/update_summary.js.haml new file mode 100644 index 00000000..251c73fb --- /dev/null +++ b/app/views/finance/balancing/update_summary.js.haml @@ -0,0 +1 @@ +$('#summary').html('#{j(render('finance/balancing/summary', order: @order))}'); \ No newline at end of file diff --git a/app/views/finance/group_order_articles/update.js.haml b/app/views/finance/group_order_articles/update.js.haml index b4ff3c4e..36e66ccd 100644 --- a/app/views/finance/group_order_articles/update.js.haml +++ b/app/views/finance/group_order_articles/update.js.haml @@ -1,4 +1,4 @@ $('#modalContainer').modal('hide'); $('#order_article_#{@order_article.id}').html('#{j(render('finance/balancing/order_article', order_article: @order_article))}'); $('#group_order_articles_#{@order_article.id}').html('#{j(render('finance/balancing/group_order_articles', order_article: @order_article))}'); -$('#summary').html('#{j(render('finance/balancing/summary', order: @order_article.order))}'); +$('#summaryChangedWarning').show(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index aa8e0e29..53bc998f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -129,6 +129,7 @@ Foodsoft::Application.routes.draw do resources :order, controller: 'balancing', path: 'balancing' do member do + get :update_summary get :edit_note put :update_note From 329c451774c57605590dd3e54fa8b185347ed9fe Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 17 Mar 2013 17:47:37 +0100 Subject: [PATCH 21/31] Fixed articles sync view. --- app/views/articles/sync.html.haml | 88 ++++++++++++++++--------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/app/views/articles/sync.html.haml b/app/views/articles/sync.html.haml index 84ac8ad7..d297c445 100644 --- a/app/views/articles/sync.html.haml +++ b/app/views/articles/sync.html.haml @@ -1,6 +1,6 @@ -%h1 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_all_supplier_articles_path(@supplier, :sync => "1") do %h2 Auslisten ... %p - unless @outlisted_articles.empty? @@ -25,47 +25,49 @@ Werten vorausgefüllt. %br/ Abweichungen zu den alten Artikeln sind gelb markiert. - %table - %tr - %th Name - %th Notiz - %th Hersteller - %th Herkunft - %th Einheit - %th GebGr - %th Preis - %th MwSt. - %th Pfand - %th Kategorie - - @updated_articles.each do |@article, unequal_attributes| - - article = Article.find(@article.id) - %tr{:style => 'color:grey'} - %td= article.name - %td= article.note - %td= article.manufacturer - %td= article.origin - %td= article.unit - %td= article.unit_quantity - %td= article.price - %td= article.tax - %td= article.deposit - %td= article.article_category.name if article.article_category + %table.table + %thead %tr - - fields_for 'articles[]', @article do |form| - %td{:style => highlight_new(unequal_attributes, :name)} - = form.text_field 'name', :size => 0 - = form.hidden_field 'shared_updated_on' - %td{:style => highlight_new(unequal_attributes, :note)}= form.text_field 'note', :size => 15 - %td{:style => highlight_new(unequal_attributes, :manufacturer)}= form.text_field 'manufacturer', :size => 10 - %td{:style => highlight_new(unequal_attributes, :origin)}= form.text_field 'origin', :size => 5 - %td{:style => highlight_new(unequal_attributes, :unit)}= form.text_field 'unit', :size => 5 - %td{:style => highlight_new(unequal_attributes, :unit_quantity)}= form.text_field 'unit_quantity', :size => 5 - %td{:style => highlight_new(unequal_attributes, :price)}= form.text_field 'price', :size => 5 - %td{:style => highlight_new(unequal_attributes, :tax)}= form.text_field 'tax', :size => 4 - %td{:style => highlight_new(unequal_attributes, :deposit)}= form.text_field 'deposit', :size => 4 - %td= select 'article[]', 'article_category_id', ArticleCategory.find(:all).collect {|a| [ a.name, a.id ] }, { :include_blank => true } + %th Name + %th Notiz + %th Hersteller + %th Herkunft + %th Einheit + %th GebGr + %th Preis + %th MwSt. + %th Pfand + %th Kategorie + %tbody + - @updated_articles.each do |updated_article, attrs| + - article = Article.find(updated_article.id) + %tr{:style => 'color:grey'} + %td= article.name + %td= article.note + %td= article.manufacturer + %td= article.origin + %td= article.unit + %td= article.unit_quantity + %td= article.price + %td= article.tax + %td= article.deposit + %td= article.article_category.name if article.article_category + %tr + = fields_for 'articles[]', updated_article do |form| + %td{:style => highlight_new(attrs, :name)} + = form.text_field 'name', :size => 0 + = form.hidden_field 'shared_updated_on' + %td{:style => highlight_new(attrs, :note)}= form.text_field 'note', class: 'input-small' + %td{:style => highlight_new(attrs, :manufacturer)}= form.text_field 'manufacturer', class: 'input-small' + %td{:style => highlight_new(attrs, :origin)}= form.text_field 'origin', class: 'input-mini' + %td{:style => highlight_new(attrs, :unit)}= form.text_field 'unit', class: 'input-mini' + %td{:style => highlight_new(attrs, :unit_quantity)}= form.text_field 'unit_quantity', class: 'input-mini' + %td{:style => highlight_new(attrs, :price)}= form.text_field 'price', class: 'input-mini' + %td{:style => highlight_new(attrs, :tax)}= form.text_field 'tax', class: 'input-mini' + %td{:style => highlight_new(attrs, :deposit)}= form.text_field 'deposit', class: 'input-mini' + %td= form.select :article_category_id, ArticleCategory.all.map {|a| [ a.name, a.id ] }, + {include_blank: true}, class: 'input-small' %hr/ = hidden_field 'supplier', 'id' - = submit_tag 'Alle löschen/aktualisieren' - | - = link_to 'Abbrechen', supplier_articles_path(@supplier) \ No newline at end of file + = submit_tag 'Alle löschen/aktualisieren', class: 'btn btn-primary' + = link_to 'oder abbrechen', supplier_articles_path(@supplier) \ No newline at end of file From 707f9897681f42ed477e8c5bd7e0d6710d944877 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 17 Mar 2013 17:50:50 +0100 Subject: [PATCH 22/31] Fixed routes in redirect after direct_close of orders. --- app/controllers/finance/balancing_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index df5eb22a..e496200a 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -57,7 +57,7 @@ class Finance::BalancingController < Finance::BaseController def close @order = Order.find(params[:id]) @order.close!(@current_user) - redirect_to finance_root_url, notice: "Bestellung wurde erfolgreich abgerechnet, die Kontostände aktualisiert." + redirect_to finance_order_index_url, notice: "Bestellung wurde erfolgreich abgerechnet, die Kontostände aktualisiert." rescue => error redirect_to new_finance_order_url(order_id: @order.id), alert: "Ein Fehler ist beim Abrechnen aufgetreten: #{error.message}" @@ -67,9 +67,9 @@ class Finance::BalancingController < Finance::BaseController def close_direct @order = Order.find(params[:id]) @order.close_direct!(@current_user) - redirect_to finance_balancing_url, notice: "Bestellung wurde geschlossen." + redirect_to finance_order_index_url, notice: "Bestellung wurde geschlossen." rescue => error - redirect_to finance_balancing_url, alert: "Bestellung kann nicht geschlossen werden: #{error.message}" + redirect_to finance_order_index_url, alert: "Bestellung kann nicht geschlossen werden: #{error.message}" end end From 3a9ec5a3dd71faaf12d38fb36028ed5323caee62 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 17 Mar 2013 17:57:35 +0100 Subject: [PATCH 23/31] Fixed wiki site-map, when there is no homepage. --- app/views/pages/_site_map.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/pages/_site_map.html.haml b/app/views/pages/_site_map.html.haml index f19afe64..da0179c3 100644 --- a/app/views/pages/_site_map.html.haml +++ b/app/views/pages/_site_map.html.haml @@ -8,5 +8,5 @@ = render :partial => 'page_list_item', :locals => {:page => homepage, :level => 0, :siteMap => 1} %tbody - for page in @pages - - if page.id != homepage.id + - if page.id != homepage.try(:id) = render :partial => 'page_list_item', :locals => {:page => page, :level => 0, :siteMap => 1} From f7e885de7e609d05e159f7084d0d349a54661f34 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 17 Mar 2013 18:10:48 +0100 Subject: [PATCH 24/31] Fixed bug in fax template when there are missing supplier infos. --- app/documents/order_fax.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/documents/order_fax.rb b/app/documents/order_fax.rb index 5dd4bfee..84ef70d6 100644 --- a/app/documents/order_fax.rb +++ b/app/documents/order_fax.rb @@ -14,28 +14,26 @@ class OrderFax < OrderPdf # From paragraph bounding_box [margin_box.right-200,margin_box.top], width: 200 do - text FoodsoftConfig[:name], align: :right + text FoodsoftConfig[:name], size: 9, align: :right move_down 5 - text contact[:street], align: :right + text contact[:street], size: 9, align: :right move_down 5 - text "#{contact[:zip_code]} #{contact[:city]}", align: :right + text "#{contact[:zip_code]} #{contact[:city]}", size: 9, align: :right move_down 5 - if @order.supplier.customer_number != '' - text "Kundennummer: #{@order.supplier.customer_number}", align: :right - end - move_down 10 - text contact[:phone], size: 9, align: :right + text "Kundennummer: #{@order.supplier.try(:customer_number)}", size: 9, align: :right move_down 5 - text contact[:email], size: 9, align: :right + text "Telefon: #{contact[:phone]}", size: 9, align: :right + move_down 5 + text "E-mail: #{contact[:email]}", size: 9, align: :right end # Recipient bounding_box [margin_box.left,margin_box.top-60], width: 200 do text @order.name move_down 5 - text @order.supplier.address + text @order.supplier.try(:address).to_s move_down 5 - text "Fax: " + @order.supplier.fax + text "Fax: #{@order.supplier.try(:fax)}" end move_down 5 @@ -44,7 +42,7 @@ class OrderFax < OrderPdf move_down 10 text "Lieferdatum:" move_down 10 - text "Ansprechpartner: " + @order.supplier.contact_person + text "Ansprechpartner: #{@order.supplier.try(:contact_person)}" move_down 10 # Articles From dd0bd0ad7e210d6b2442158fa15357493936c268 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 17 Mar 2013 18:33:04 +0100 Subject: [PATCH 25/31] Fixed updating order article in stockit balancing. --- .../finance/order_articles_controller.rb | 2 +- app/models/order_article.rb | 30 ++++++++++--------- .../finance/order_articles/_edit.html.haml | 18 ++++++----- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/controllers/finance/order_articles_controller.rb b/app/controllers/finance/order_articles_controller.rb index 13c1106c..edd0fd82 100644 --- a/app/controllers/finance/order_articles_controller.rb +++ b/app/controllers/finance/order_articles_controller.rb @@ -26,7 +26,7 @@ class Finance::OrderArticlesController < ApplicationController @order = Order.find(params[:order_id]) @order_article = OrderArticle.find(params[:id]) begin - @order_article.update_article_and_price!(params[:article], params[:article_price], params[:order_article]) + @order_article.update_article_and_price!(params[:order_article], params[:article], params[:article_price]) rescue render action: :edit end diff --git a/app/models/order_article.rb b/app/models/order_article.rb index af257f5d..192d60d5 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -93,7 +93,7 @@ class OrderArticle < ActiveRecord::Base end # Updates order_article and belongings during balancing process - def update_article_and_price!(article_attributes, price_attributes, order_article_attributes) + def update_article_and_price!(order_article_attributes, article_attributes, price_attributes = nil) OrderArticle.transaction do # Updates self self.update_attributes!(order_article_attributes) @@ -102,20 +102,22 @@ class OrderArticle < ActiveRecord::Base article.update_attributes!(article_attributes) # Updates article_price belonging to current order article - article_price.attributes = price_attributes - if article_price.changed? - # Updates also price attributes of article if update_current_price is selected - if update_current_price - article.update_attributes!(price_attributes) - self.article_price = article.article_prices.first # Assign new created article price to order article - else - # Creates a new article_price if neccessary - # Set created_at timestamp to order ends, to make sure the current article price isn't changed - create_article_price!(price_attributes.merge(created_at: order.ends)) and save - end + if price_attributes.present? + article_price.attributes = price_attributes + if article_price.changed? + # Updates also price attributes of article if update_current_price is selected + if update_current_price + article.update_attributes!(price_attributes) + self.article_price = article.article_prices.first # Assign new created article price to order article + else + # Creates a new article_price if neccessary + # Set created_at timestamp to order ends, to make sure the current article price isn't changed + create_article_price!(price_attributes.merge(created_at: order.ends)) and save + end - # Updates ordergroup values - update_ordergroup_prices + # Updates ordergroup values + update_ordergroup_prices + end end end end diff --git a/app/views/finance/order_articles/_edit.html.haml b/app/views/finance/order_articles/_edit.html.haml index 13432620..c2b92be6 100644 --- a/app/views/finance/order_articles/_edit.html.haml +++ b/app/views/finance/order_articles/_edit.html.haml @@ -5,18 +5,20 @@ .modal-body = form.input :units_to_order - = simple_fields_for @order_article.article do |f| + = simple_fields_for :article, @order_article.article do |f| = f.input :name = f.input :order_number = f.input :unit - = simple_fields_for @order_article.article_price do |f| - = f.input :unit_quantity - = f.input :price - = f.input :tax - = f.input :deposit - - = form.input :update_current_price, as: :boolean + - if @order_article.article.is_a?(StockArticle) + %div.alert Preise von Lagerartikeln können nicht geändert werden! + - else + = simple_fields_for :article_price, @order_article.article_price do |f| + = f.input :unit_quantity + = f.input :price + = f.input :tax + = f.input :deposit + = form.input :update_current_price, as: :boolean .modal-footer = button_tag "Schließen", class: 'btn', data: {dismiss: 'modal'} = form.submit class: 'btn btn-primary' \ No newline at end of file From 59de2e42a9e1cbb047685f9a8802054bd162b101 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 17 Mar 2013 18:36:17 +0100 Subject: [PATCH 26/31] Fixed showing deleted articles when asking for available articles. --- app/models/article.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/article.rb b/app/models/article.rb index 852bed32..08088f09 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -11,7 +11,7 @@ class Article < ActiveRecord::Base has_many :article_prices, :order => "created_at DESC" scope :undeleted, -> { where(deleted_at: nil) } - scope :available, :conditions => {:availability => true} + scope :available, -> { undeleted.where(availability: true) } scope :not_in_stock, :conditions => {:type => nil} # Validations From 6745b79bb9cda08c6be9cc4dd6fa1050e93b8060 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 17 Mar 2013 20:02:14 +0100 Subject: [PATCH 27/31] Allow importing articles again, when article was deleted before. --- app/views/articles/_import_search_results.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/articles/_import_search_results.haml b/app/views/articles/_import_search_results.haml index 1a43165f..6a316af0 100644 --- a/app/views/articles/_import_search_results.haml +++ b/app/views/articles/_import_search_results.haml @@ -25,7 +25,7 @@ %td= article.unit_quantity %td - logger.debug "[debug] #{article.attributes.inspect}" - - if @supplier.articles.where(order_number: article.number).exists? + - if @supplier.articles.undeleted.where(order_number: article.number).exists? %i.icon-ok schon importiert - else From 528295884e8e6da4a7b372e06b5943d5e9bc794c Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 17 Mar 2013 20:11:57 +0100 Subject: [PATCH 28/31] Allow deleting of category, when there are only deleted articles left. --- app/models/article_category.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/article_category.rb b/app/models/article_category.rb index bd0e3d68..c93e1c31 100644 --- a/app/models/article_category.rb +++ b/app/models/article_category.rb @@ -8,7 +8,7 @@ class ArticleCategory < ActiveRecord::Base protected def check_for_associated_articles - raise I18n.t('activerecord.errors.has_many_left', collection: Article.model_name.human) if articles.exists? + raise I18n.t('activerecord.errors.has_many_left', collection: Article.model_name.human) if articles.undeleted.exists? end end From e275403cdd57448f35147bcd3fa1bd192783e702 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Mon, 18 Mar 2013 19:05:11 +0100 Subject: [PATCH 29/31] Do not destroy articles in supplier sync. Mark them as deleted. --- app/controllers/articles_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index a9af168e..820242d6 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -92,7 +92,7 @@ class ArticlesController < ApplicationController end # delete articles if params[:outlisted_articles] - params[:outlisted_articles].keys.each {|id| Article.find(id).destroy } + params[:outlisted_articles].keys.each {|id| Article.find(id).mark_as_deleted } end end # Successfully done. From 957dbc7202fcd86609af62e910d6e554f184d34f Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Tue, 19 Mar 2013 13:18:48 +0100 Subject: [PATCH 30/31] Updated to rails 3.2.13 --- Gemfile.lock | 74 ++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index aabdad24..068602a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,32 +22,32 @@ GEM remote: https://rubygems.org/ specs: Ascii85 (1.0.2) - actionmailer (3.2.11) - actionpack (= 3.2.11) - mail (~> 2.4.4) - actionpack (3.2.11) - activemodel (= 3.2.11) - activesupport (= 3.2.11) + actionmailer (3.2.13) + actionpack (= 3.2.13) + mail (~> 2.5.3) + actionpack (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) - rack (~> 1.4.0) + rack (~> 1.4.5) rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) - activemodel (3.2.11) - activesupport (= 3.2.11) + activemodel (3.2.13) + activesupport (= 3.2.13) builder (~> 3.0.0) - activerecord (3.2.11) - activemodel (= 3.2.11) - activesupport (= 3.2.11) + activerecord (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activeresource (3.2.11) - activemodel (= 3.2.11) - activesupport (= 3.2.11) - activesupport (3.2.11) - i18n (~> 0.6) + activeresource (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) + activesupport (3.2.13) + i18n (= 0.6.1) multi_json (~> 1.0) acts_as_tree (1.2.0) activerecord (>= 3.0.0) @@ -94,7 +94,7 @@ GEM jquery-rails (2.1.3) railties (>= 3.1.0, < 5.0) thor (~> 0.14) - json (1.7.6) + json (1.7.7) kaminari (0.14.1) actionpack (>= 3.0.0) activesupport (>= 3.0.0) @@ -104,7 +104,7 @@ GEM actionpack (>= 3.1) less (~> 2.2.0) libv8 (3.3.10.4) - mail (2.4.4) + mail (2.5.3) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) @@ -113,8 +113,8 @@ GEM activerecord (~> 3.1) activesupport (~> 3.1) polyamorous (~> 0.5.0) - mime-types (1.19) - multi_json (1.5.0) + mime-types (1.21) + multi_json (1.7.1) mysql2 (0.3.11) pdf-reader (1.2.0) Ascii85 (~> 1.0.0) @@ -126,32 +126,32 @@ GEM prawn (0.12.0) pdf-reader (>= 0.9.0) ttfunk (~> 1.0.2) - rack (1.4.3) + rack (1.4.5) rack-cache (1.2) rack (>= 0.4) rack-protection (1.3.2) rack - rack-ssl (1.3.2) + rack-ssl (1.3.3) rack rack-test (0.6.2) rack (>= 1.0) - rails (3.2.11) - actionmailer (= 3.2.11) - actionpack (= 3.2.11) - activerecord (= 3.2.11) - activeresource (= 3.2.11) - activesupport (= 3.2.11) + rails (3.2.13) + actionmailer (= 3.2.13) + actionpack (= 3.2.13) + activerecord (= 3.2.13) + activeresource (= 3.2.13) + activesupport (= 3.2.13) bundler (~> 1.0) - railties (= 3.2.11) - railties (3.2.11) - actionpack (= 3.2.11) - activesupport (= 3.2.11) + railties (= 3.2.13) + railties (3.2.13) + actionpack (= 3.2.13) + activesupport (= 3.2.13) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.0.3) - rdoc (3.12) + rdoc (3.12.2) json (~> 1.4) redis (3.0.2) redis-namespace (1.2.1) @@ -190,8 +190,8 @@ GEM test-unit (2.5.3) therubyracer (0.10.2) libv8 (~> 3.3.10) - thor (0.16.0) - tilt (1.3.3) + thor (0.17.0) + tilt (1.3.6) treetop (1.4.12) polyglot polyglot (>= 0.3.1) @@ -201,7 +201,7 @@ GEM less-rails (~> 2.2.3) railties (>= 3.1) therubyracer (~> 0.10.2) - tzinfo (0.3.35) + tzinfo (0.3.37) uglifier (1.3.0) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) From 22550029b308ee9ebc25e7b1829e1f8f39522f3e Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Wed, 20 Mar 2013 23:31:13 +0100 Subject: [PATCH 31/31] Added missing ajax support for messages index. Fixed #101 --- app/views/messages/index.js.haml | 1 + 1 file changed, 1 insertion(+) create mode 100644 app/views/messages/index.js.haml diff --git a/app/views/messages/index.js.haml b/app/views/messages/index.js.haml new file mode 100644 index 00000000..90dcadd3 --- /dev/null +++ b/app/views/messages/index.js.haml @@ -0,0 +1 @@ +$('#messages').html('#{j(render('messages', messages: @messages, pagination: true))}'); \ No newline at end of file