Fixed wrong price value of GroupOrder when finishing an order.

This commit is contained in:
Benjamin Meichsner 2009-03-11 16:34:36 +01:00
parent dd940fb414
commit 37c9e2aeaf
2 changed files with 11 additions and 3 deletions

View file

@ -30,11 +30,16 @@ class GroupOrder < ActiveRecord::Base
named_scope :finished, lambda { {:conditions => ["order_id IN (?)", Order.finished.collect(&:id)]} } named_scope :finished, lambda { {:conditions => ["order_id IN (?)", Order.finished.collect(&:id)]} }
# Updates the "price" attribute. # Updates the "price" attribute.
# This will be the maximum value of an order # This will be the maximum value of an open order or
# the value depending of the article results.
def update_price! def update_price!
total = 0 total = 0
for article in group_order_articles.find(:all, :include => :order_article) for article in group_order_articles.find(:all, :include => :order_article)
unless order.finished?
total += article.order_article.article.fc_price * (article.quantity + article.tolerance) total += article.order_article.article.fc_price * (article.quantity + article.tolerance)
else
total += article.order_article.price.fc_price * article.result
end
end end
update_attribute(:price, total) update_attribute(:price, total)
end end

View file

@ -170,6 +170,9 @@ class Order < ActiveRecord::Base
oa.update_attribute(:article_price, oa.article.article_prices.first) oa.update_attribute(:article_price, oa.article.article_prices.first)
oa.group_order_articles.each { |goa| goa.save_results! } oa.group_order_articles.each { |goa| goa.save_results! }
end end
# Update GroupOrder prices
group_orders.each { |go| go.update_price! }
# set new order state (needed by notify_order_finished) # set new order state (needed by notify_order_finished)
update_attributes(:state => 'finished', :ends => Time.now, :updated_by => user) update_attributes(:state => 'finished', :ends => Time.now, :updated_by => user)