Fixed bug order.profit calculation.

Order.profit will also be saved, when order is closed.
This commit is contained in:
Benjamin Meichsner 2009-03-17 19:43:41 +01:00
parent 843e4a7233
commit da08365816
32 changed files with 408 additions and 34 deletions

View file

@ -80,7 +80,7 @@ class ApplicationController < ActionController::Base
if !(user = current_user)
# No user at all: redirect to login page.
self.return_to = request.request_uri
redirect_to :controller => 'login'
redirect_to :controller => '/login'
return false
else
# We have an authenticated user, now check role...

View file

@ -1,5 +1,5 @@
# == Schema Information
# Schema version: 20090119155930
# Schema version: 20090317175355
#
# Table name: orders
#
@ -11,6 +11,7 @@
# state :string(255) default("open")
# lock_version :integer default(0), not null
# updated_by_user_id :integer
# foodcoop_result :decimal(8, 2)
#
class Order < ActiveRecord::Base
@ -117,10 +118,11 @@ class Order < ActiveRecord::Base
# Returns the defecit/benefit for the foodcoop
# Requires a valid invoice, belonging to this order
#FIXME: Consider order.foodcoop_result
def profit(options = {})
markup = options[:with_markup] || true
markup = options[:without_markup] || false
if invoice
groups_sum = markup ? sum(:groups) : sum(:groups_without_markup)
groups_sum = markup ? sum(:groups_without_markup) : sum(:groups)
groups_sum - invoice.net_amount
end
end
@ -145,8 +147,8 @@ class Order < ActiveRecord::Base
end
end
elsif type == :groups || type == :groups_without_markup
for go in group_orders
for goa in go.group_order_articles
for go in group_orders.all(:include => :group_order_articles)
for goa in go.group_order_articles.all(:include => [:order_article])
case type
when :groups
total += goa.result * goa.order_article.price.fc_price
@ -208,7 +210,7 @@ class Order < ActiveRecord::Base
end
end
self.update_attributes! :state => 'closed', :updated_by => user
self.update_attributes! :state => 'closed', :updated_by => user, :foodcoop_result => profit
end
end

View file

@ -1,5 +1,5 @@
# == Schema Information
# Schema version: 20090120184410
# Schema version: 20090317175355
#
# Table name: stock_changes
#
@ -9,6 +9,7 @@
# stock_article_id :integer
# quantity :integer default(0)
# created_at :datetime
# stock_taking_id :integer
#
class StockChange < ActiveRecord::Base

View file

@ -1,3 +1,14 @@
# == Schema Information
# Schema version: 20090317175355
#
# Table name: stock_takings
#
# id :integer not null, primary key
# date :date
# note :text
# created_at :datetime
#
class StockTaking < ActiveRecord::Base
has_many :stock_changes, :dependent => :destroy

View file

@ -17,7 +17,7 @@
%td= number_to_currency(order.sum(:groups))
%tr
%td FC Gewinn ohne Aufschlag:
%td= number_to_currency(order.profit(:with_markup => false))
%td= number_to_currency(order.profit(:without_markup => true))
%tr
%td FC Gewinn mit Aufschlag:
%td#order_profit= number_to_currency(order.profit)

View file

@ -20,7 +20,7 @@
%tr{:class => cycle("even","odd", :name => "order")}
%td= link_to truncate(order.name), :action => "new", :id => order
%td=h format_time(order.ends) unless order.ends.nil?
%td= order.closed? ? "abgerechnet (#{number_to_currency order.profit})" : "beendet"
%td= order.closed? ? "abgerechnet (#{number_to_currency order.foodcoop_result})" : "beendet"
%td= order.updated_by.nil? ? '??' : order.updated_by.nick
%td
- unless order.closed?