From 7e0a4acf596fa773429e7c0eb496b524699629c6 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Tue, 26 Feb 2013 10:05:37 +0100 Subject: [PATCH 01/11] 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 2f109c376df1632599ee911ebe0405dfb3027b02 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Tue, 26 Feb 2013 10:59:05 +0100 Subject: [PATCH 02/11] 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 03/11] 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 04/11] 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 05/11] 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 06/11] 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 07/11] 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 08/11] 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 09/11] 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 10/11] 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 11/11] 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