From 497c9e0cf1ba60ce709aa69c39c60bfd71ae206f Mon Sep 17 00:00:00 2001 From: wvengen Date: Tue, 2 Jul 2013 12:01:25 +0200 Subject: [PATCH 1/2] fix closed group_order totals --- app/models/group_order_article.rb | 2 +- .../20130702113610_update_group_order_totals.rb | 12 ++++++++++++ db/schema.rb | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20130702113610_update_group_order_totals.rb diff --git a/app/models/group_order_article.rb b/app/models/group_order_article.rb index 11f3b447..36e67828 100644 --- a/app/models/group_order_article.rb +++ b/app/models/group_order_article.rb @@ -167,7 +167,7 @@ class GroupOrderArticle < ActiveRecord::Base # the minimum price depending on configuration. When the order is finished it # will be the value depending of the article results. def total_price(order_article = self.order_article) - unless order_article.order.finished? + if order_article.order.open? if FoodsoftConfig[:tolerance_is_costly] order_article.article.fc_price * (quantity + tolerance) else diff --git a/db/migrate/20130702113610_update_group_order_totals.rb b/db/migrate/20130702113610_update_group_order_totals.rb new file mode 100644 index 00000000..4e45749f --- /dev/null +++ b/db/migrate/20130702113610_update_group_order_totals.rb @@ -0,0 +1,12 @@ +class UpdateGroupOrderTotals < ActiveRecord::Migration + def self.up + # The group_order total was updated to the total ordered amount instead of + # the amount received. Now this is fixed, the totals need to be updated. + GroupOrder.all.each do |go| + go.order.closed? and go.update_price! + end + end + + def self.down + end +end diff --git a/db/schema.rb b/db/schema.rb index 188ea83b..59f35c66 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20121230142516) do +ActiveRecord::Schema.define(:version => 20130715233410) do create_table "article_categories", :force => true do |t| t.string "name", :default => "", :null => false From 2d549fc1daf85f81acb3c9b5a8d54bd13641d7db Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Sep 2013 18:33:49 +0200 Subject: [PATCH 2/2] do not recalculate GroupOrder totals, but show message to do so on migrations --- .../20130702113610_update_group_order_totals.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/db/migrate/20130702113610_update_group_order_totals.rb b/db/migrate/20130702113610_update_group_order_totals.rb index 4e45749f..ca9aab67 100644 --- a/db/migrate/20130702113610_update_group_order_totals.rb +++ b/db/migrate/20130702113610_update_group_order_totals.rb @@ -1,10 +1,16 @@ class UpdateGroupOrderTotals < ActiveRecord::Migration def self.up - # The group_order total was updated to the total ordered amount instead of - # the amount received. Now this is fixed, the totals need to be updated. - GroupOrder.all.each do |go| - go.order.closed? and go.update_price! - end + say "If you have ever modified an order after it was settled, the group_order's " + + "price may be calculated incorrectly. This can take a lot of time on a " + + "large database." + + say "If you do want to update the ordergroup totals, open the rails console " + + "(by running `rails c`), and enter:" + + say "GroupOrder.all.each { |go| go.order.closed? and go.update_price! }", subitem: true + + say "You may want to check first that no undesired accounting issues are introduced. " + + "It may be wise to discuss this with those responsible for the ordering finances." end def self.down