Added percent fields and changed the setters on Deliverables to save the values. #1135
This commit is contained in:
@@ -4,13 +4,6 @@ class Deliverable < ActiveRecord::Base
|
||||
|
||||
belongs_to :project
|
||||
|
||||
attr_accessor :overhead
|
||||
attr_accessor :materials
|
||||
attr_accessor :profit
|
||||
attr_accessor :cost_per_hour
|
||||
attr_accessor :total_hours
|
||||
attr_accessor :fixed_cost
|
||||
|
||||
# TODO: mocked
|
||||
def score
|
||||
0
|
||||
@@ -25,4 +18,46 @@ class Deliverable < ActiveRecord::Base
|
||||
def progress
|
||||
0
|
||||
end
|
||||
|
||||
#
|
||||
# These attributes can take a Dollar amount or a %
|
||||
#
|
||||
def overhead=(v)
|
||||
if v.match(/%/)
|
||||
# Clear amount since this is a %
|
||||
write_attribute(:overhead, nil)
|
||||
write_attribute(:overhead_percent, v.gsub(/[% ]/,''))
|
||||
else
|
||||
# Clear % since this is a dollar amount
|
||||
write_attribute(:overhead_percent, nil)
|
||||
# Take out $, commas, and spaces
|
||||
write_attribute(:overhead, v.gsub(/[$, ]/,''))
|
||||
end
|
||||
end
|
||||
|
||||
def materials=(v)
|
||||
if v.match(/%/)
|
||||
# Clear amount since this is a %
|
||||
write_attribute(:materials, nil)
|
||||
write_attribute(:materials_percent, v.gsub(/[% ]/,''))
|
||||
else
|
||||
# Clear % since this is a dollar amount
|
||||
write_attribute(:materials_percent, nil)
|
||||
# Take out $, commas, and spaces
|
||||
write_attribute(:materials, v.gsub(/[$, ]/,''))
|
||||
end
|
||||
end
|
||||
|
||||
def profit=(v)
|
||||
if v.match(/%/)
|
||||
# Clear amount since this is a %
|
||||
write_attribute(:profit, nil)
|
||||
write_attribute(:profit_percent, v.gsub(/[% ]/,''))
|
||||
else
|
||||
# Clear % since this is a dollar amount
|
||||
write_attribute(:profit_percent, nil)
|
||||
# Take out $, commas, and spaces
|
||||
write_attribute(:profit, v.gsub(/[$, ]/,''))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user