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,12 +30,17 @@ class GroupOrder < ActiveRecord::Base
named_scope :finished, lambda { {:conditions => ["order_id IN (?)", Order.finished.collect(&:id)]} }
# 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!
total = 0
for article in group_order_articles.find(:all, :include => :order_article)
total += article.order_article.article.fc_price * (article.quantity + article.tolerance)
end
unless order.finished?
total += article.order_article.article.fc_price * (article.quantity + article.tolerance)
else
total += article.order_article.price.fc_price * article.result
end
end
update_attribute(:price, total)
end

View File

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