allows overriding costs in cost_entries.

git-svn-id: https://dev.finn.de/svn/cockpit/trunk@84 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
hjust 15 years ago
parent 1325e0a3fd
commit b221a43454
  1. 3
      app/controllers/costlog_controller.rb
  2. 4
      app/controllers/deliverables_controller.rb
  3. 4
      app/models/cost_based_deliverable.rb
  4. 24
      app/models/cost_entry.rb
  5. 19
      app/views/costlog/edit.rhtml
  6. 5
      app/views/deliverables/_show_cost_based_deliverable.rhtml
  7. 4
      db/migrate/010_add_free_text_to_budget_and_entries.rb

@ -91,6 +91,9 @@ class CostlogController < ApplicationController
new_user ||= User.current
@cost_entry = CostEntry.new(:project => @project, :issue => @issue, :user => new_user, :spent_on => Date.today)
end
if params[:cost_entry].is_a?(Hash) && !params[:cost_entry][:costs]
params[:cost_entry][:costs] = nil
end
@cost_entry.attributes = params[:cost_entry]
@cost_entry.cost_type ||= CostType.default

@ -147,7 +147,6 @@ class DeliverablesController < ApplicationController
def update_deliverable_cost
element_id = params[:element_id] if params.has_key? :element_id
render_403 and return unless element_id =~ /^deliverable_(existing|new)_deliverable_cost_attributes_[0-9]+$/
cost_type = CostType.find(params[:cost_type_id]) if params.has_key? :cost_type_id
@ -168,8 +167,7 @@ class DeliverablesController < ApplicationController
def update_deliverable_hour
element_id = params[:element_id] if params.has_key? :element_id
render_403 and return unless element_id =~ /^deliverable_(existing|new)_deliverable_hour_attributes_[0-9]+$/
user = User.find(params[:user_id])
hours = params[:hours].to_hours

@ -98,12 +98,12 @@ class CostBasedDeliverable < Deliverable
private
def clean_currency(value)
if value
if value && value.is_a?(String)
value = value.strip
value.gsub!(l(:currency_delimiter), '') if value.include?(l(:currency_delimiter)) && value.include?(l(:currency_seperator))
value.gsub(',', '.')
else
nil
value
end
end
end

@ -33,8 +33,20 @@ class CostEntry < ActiveRecord::Base
errors.add :user_id, :activerecord_error_invalid unless (user == User.current) || (User.current.allowed_to? :book_costs, project)
end
# def overridden_costs=(value)
# self.attributes[:overridden_costs] = value
# end
def costs
@costs || units * cost_type.rate_at(self.spent_on).rate
self.overridden_costs || calculated_costs
end
def costs=(value)
self.overridden_costs = value
end
def calculated_costs
units * cost_type.rate_at(self.spent_on).rate
rescue
0.0
end
@ -50,4 +62,14 @@ class CostEntry < ActiveRecord::Base
end
end
private
def clean_currency(value)
if value && value.is_a?(String)
value = value.strip
value.gsub!(l(:currency_delimiter), '') if value.include?(l(:currency_delimiter)) && value.include?(l(:currency_seperator))
value.gsub(',', '.')
else
value
end
end
end

@ -13,11 +13,26 @@
<p><%= f.select :cost_type_id, cost_types_collection_for_select_options, :required => true %></p>
<p>
<%= f.text_field :units, :size => 6, :required => true %>
<span id="cost_type_unit_plural"><%= render :partial => "cost_type_unit_plural", :locals => {:cost_type => @cost_entry.cost_type} %></span>
<%= observe_field ('cost_entry_cost_type_id', :update => 'cost_type_unit_plural', :url => {:action => :get_cost_type_unit_plural}, :with => :cost_type_id) %>
<span id="cost_entry_unit_name"><%= @cost_entry.units == 1 ? @cost_entry.cost_type.unit : @cost_entry.cost_type.unit_plural %></span>
<%= observe_field( "cost_entry_cost_type_id", :url => {:controller => :deliverables, :action => :update_deliverable_cost, :project_id => @cost_entry.project}, :with => "'cost_type_id=' + encodeURIComponent(value) + '&units=' + encodeURIComponent(document.getElementById('cost_entry_units').value) + '&fixed_date=' + encodeURIComponent(document.getElementById('cost_entry_spent_on').value) + '&element_id=cost_entry'") %>
<%= observe_field( "cost_entry_units", :frequency => 1, :url => {:controller => :deliverables, :action => :update_deliverable_cost, :project_id => @cost_entry.project}, :with => "'cost_type_id=' + encodeURIComponent(document.getElementById('cost_entry_cost_type_id').value) + '&units=' + encodeURIComponent(value) + '&fixed_date=' + encodeURIComponent(document.getElementById('cost_entry_spent_on').value) + '&element_id=cost_entry'") %>
<%= observe_field( "cost_entry_spent_on", :frequency => 1, :url => {:controller => :deliverables, :action => :update_deliverable_cost, :project_id => @cost_entry.project}, :with => "'cost_type_id=' + encodeURIComponent(document.getElementById('cost_entry_cost_type_id').value) + '&units=' + encodeURIComponent(document.getElementById('cost_entry_units').value) + '&fixed_date=' + encodeURIComponent(value) + '&element_id=cost_entry'") %>
</p>
<p>
<label><%= l(:field_costs) %></label>
<span id="cost_entry_costs"><%= number_to_currency(@cost_entry.calculated_costs) %></span>
<%= update_page_tag do |page|
page << "makeEditable('cost_entry_costs', 'cost_entry[costs]');"
page << "edit($('cost_entry_costs'), 'cost_entry[budget]', '#{number_to_currency(@cost_entry.overridden_costs)}');" if @cost_entry.overridden_costs
end %>
</p>
<p><%= f.text_field :comments, :size => 100 %></p>
</div>
<%= submit_tag l(:button_save) %>
<% end %>
<% content_for :header_tags do %>
<%= javascript_include_tag 'editinplace', :plugin => 'redmine_costs' %>
<% end %>

@ -36,10 +36,13 @@
cost_entries = issue.cost_entries.inject(Hash.new) do |results, entry|
result = results[entry.cost_type.id.to_s]
unless result
result = CostEntry.new(:cost_type => entry.cost_type, :deliverable => @deliverable, :costs => 0, :units => 0)
result = CostEntry.new(:cost_type => entry.cost_type, :deliverable => @deliverable, :overridden_costs => 0.0, :units => 0)
results[entry.cost_type.id.to_s] = result
end
p result.costs
p entry.costs
result.costs += entry.costs
result.units += entry.units
results

@ -3,13 +3,13 @@ class AddFreeTextToBudgetAndEntries < ActiveRecord::Migration
add_column :deliverable_costs, :budget, :decimal, :precision => 15, :scale => 2, :null => true
add_column :deliverable_hours, :budget, :decimal, :precision => 15, :scale => 2, :null => true
add_column :cost_entries, :costs, :decimal, :precision => 15, :scale => 2, :null => true
add_column :cost_entries, :overridden_cost, :decimal, :precision => 15, :scale => 2, :null => true
end
def self.down
remove_column :deliverable_costs, :budget
remove_column :deliverable_hours, :budget
remove_column :cost_entries, :costs
remove_column :cost_entries, :overridden_cost
end
end
Loading…
Cancel
Save