Consider task duration in ordergroup stats.

* Also added duration to task template in workgroup task_duration.
This commit is contained in:
benni 2011-05-07 21:54:00 +02:00
parent be85296ddb
commit c2496aa4fd
19 changed files with 80 additions and 32 deletions

View file

@ -49,7 +49,7 @@ end
# type :string(255) default(""), not null
# name :string(255) default(""), not null
# description :string(255)
# account_balance :decimal(8, 2) default(0.0), not null
# account_balance :decimal(, ) default(0.0), not null
# account_updated :datetime
# created_on :datetime not null
# role_admin :boolean default(FALSE), not null
@ -67,5 +67,6 @@ end
# contact_phone :string(255)
# contact_address :string(255)
# stats :text
# task_duration :integer default(1)
#

View file

@ -53,7 +53,7 @@ class Ordergroup < Group
def update_stats!
time = 6.month.ago
jobs = users.collect { |u| u.tasks.done.all(:conditions => ["updated_on > ?", time]).size }.sum
jobs = users.collect { |u| u.tasks.done.sum('duration', :conditions => ["updated_on > ?", time]) }.sum
orders_sum = group_orders.select { |go| !go.order.ends.nil? && go.order.ends > time }.collect(&:price).sum
update_attribute(:stats, {:jobs_size => jobs, :orders_sum => orders_sum})
end
@ -91,7 +91,7 @@ end
# type :string(255) default(""), not null
# name :string(255) default(""), not null
# description :string(255)
# account_balance :decimal(8, 2) default(0.0), not null
# account_balance :decimal(, ) default(0.0), not null
# account_updated :datetime
# created_on :datetime not null
# role_admin :boolean default(FALSE), not null
@ -109,5 +109,6 @@ end
# contact_phone :string(255)
# contact_address :string(255)
# stats :text
# task_duration :integer default(1)
#

View file

@ -11,6 +11,7 @@ class Task < ActiveRecord::Base
attr_protected :users
validates_length_of :name, :minimum => 3
validates_numericality_of :duration, :in => 1..3
after_save :update_ordergroup_stats
@ -67,7 +68,7 @@ class Task < ActiveRecord::Base
def update_ordergroup_stats
if done
users.each { |u| u.ordergroup.update_stats! }
users.each { |u| u.ordergroup.update_stats! if u.ordergroup }
end
end
end
@ -87,6 +88,6 @@ end
# updated_on :datetime not null
# required_users :integer default(1)
# weekly :boolean
# duration :integer
# duration :integer default(1)
#

View file

@ -34,11 +34,12 @@ class Workgroup < Group
def task_attributes(date)
{
:name => task_name,
:description => task_description,
:due_date => date,
:required_users => task_required_users,
:weekly => true
:name => task_name,
:description => task_description,
:due_date => date,
:required_users => task_required_users,
:duration => task_duration,
:weekly => true
}
end
@ -52,7 +53,7 @@ end
# type :string(255) default(""), not null
# name :string(255) default(""), not null
# description :string(255)
# account_balance :decimal(8, 2) default(0.0), not null
# account_balance :decimal(, ) default(0.0), not null
# account_updated :datetime
# created_on :datetime not null
# role_admin :boolean default(FALSE), not null
@ -70,5 +71,6 @@ end
# contact_phone :string(255)
# contact_address :string(255)
# stats :text
# task_duration :integer default(1)
#