From 14f00375a20099f05858cf783c042b80ec2bc30e Mon Sep 17 00:00:00 2001 From: hjust Date: Thu, 10 Sep 2009 10:44:44 +0000 Subject: [PATCH] * allow to define a labor budget for users without a rate * fixed display bug if user has no rate for a fixed anymore * allowe to remove all rates for a user git-svn-id: https://dev.finn.de/svn/cockpit/trunk@111 7926756e-e54e-46e6-9721-ed318f58905e --- app/controllers/hourly_rates_controller.rb | 12 +++++++++--- app/models/deliverable_cost.rb | 6 +++++- app/models/deliverable_hour.rb | 6 +++++- app/views/deliverables/_deliverable_hour.rhtml | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/controllers/hourly_rates_controller.rb b/app/controllers/hourly_rates_controller.rb index 2996a04f6d..0b26362928 100644 --- a/app/controllers/hourly_rates_controller.rb +++ b/app/controllers/hourly_rates_controller.rb @@ -35,17 +35,23 @@ class HourlyRatesController < ApplicationController existing_attributes = params[:user][:existing_rate_attributes] unless existing_attributes.nil? + # this selects all rate_ids for the current user and the current project rate_ids = HourlyRate.count(:conditions => {:user_id => @user, :project_id => @project}, :group => :id, :select => [:id]).to_hash - + existing_attributes = existing_attributes.reject{|a| rate_ids.has_key? a.id} end - + else + new_attributes = nil + existing_attributes = {} + end + + if request.post? @user.new_rate_attributes = new_attributes if new_attributes @user.existing_rate_attributes = existing_attributes end - + if request.post? && @user.save flash[:notice] = l(:notice_successful_update) redirect_back_or_default(:action => 'show', :id => @user, :project_id => @project) diff --git a/app/models/deliverable_cost.rb b/app/models/deliverable_cost.rb index 9fdc4f1978..3f46c32fb4 100644 --- a/app/models/deliverable_cost.rb +++ b/app/models/deliverable_cost.rb @@ -9,6 +9,10 @@ class DeliverableCost < ActiveRecord::Base end def calculated_costs - units && cost_type ? cost_type.rate_at(deliverable.fixed_date).rate * units : 0.0 + if units && cost_type && rate = cost_type.rate_at(deliverable.fixed_date) + rate.rate * units + else + 0.0 + end end end \ No newline at end of file diff --git a/app/models/deliverable_hour.rb b/app/models/deliverable_hour.rb index 18f50ad928..d96068a9ac 100644 --- a/app/models/deliverable_hour.rb +++ b/app/models/deliverable_hour.rb @@ -11,7 +11,11 @@ class DeliverableHour < ActiveRecord::Base end def calculated_costs - hours && user ? user.rate_at(deliverable.fixed_date, deliverable.project_id).rate * hours : 0.0 + if user && hours && rate = user.rate_at(deliverable.fixed_date, deliverable.project_id) + rate.rate * hours + else + 0.0 + end end def can_view_costs?(usr, project) diff --git a/app/views/deliverables/_deliverable_hour.rhtml b/app/views/deliverables/_deliverable_hour.rhtml index eae949e0fc..012504736e 100644 --- a/app/views/deliverables/_deliverable_hour.rhtml +++ b/app/views/deliverables/_deliverable_hour.rhtml @@ -18,7 +18,7 @@ <%= cost_form.text_field :hours, :index => id_or_index, :size => 3 %> - <%= cost_form.select :user_id, @project.assignable_users.sort.select{|u| u.rate_at(@deliverable.fixed_date, @project)}.collect{|u| [u.name, u.id]}, {:prompt => true}, {:index => id_or_index} %> + <%= cost_form.select :user_id, @project.assignable_users.sort.collect{|u| [u.name, u.id]}, {:prompt => true}, {:index => id_or_index} %> <%= cost_form.text_field :comments, :index => id_or_index, :size => 40 %>