Added company info revisioning in the models (refs: #ba1a26)

* Extended CompanyInfo with an "original" association with the previous
  revision (in case revisions can be removed in the future).
* Created a belongs_to relation of Invoice with CompanyInfo and an
  has_many reverse relation.
This commit is contained in:
Paul van Tilburg 2012-01-09 15:48:20 +01:00
parent 14b7a8fd4a
commit 016cb0b21d
1 changed files with 31 additions and 0 deletions

View File

@ -311,6 +311,7 @@ module StopTime::Models
#
# === Attributes by association
#
# [company_info] associated company info (CompanyInfo)
# [customer] associated customer (Customer)
# [tasks] billed tasks by the invoice (Array of Task)
# [time_entries] billed time entries (Array of TimeEntry)
@ -318,6 +319,7 @@ module StopTime::Models
has_many :tasks
has_many :time_entries, :through => :tasks
belongs_to :customer
belongs_to :company_info
# Returns a time and cost summary of the contained tasks (Hash of
# Task to Array).
@ -371,7 +373,19 @@ module StopTime::Models
# [accountiban] international bank account number (String)
# [created_at] time of creation (Time)
# [updated_at] time of last update (Time)
#
# === Attributes by association
#
# [invoices] associated invoices (Array of Invoice)
# [original] original (previous) revision (CompanyInfo)
class CompanyInfo < Base
belongs_to :original, :class_name => "CompanyInfo"
has_many :invoices
# Returns the revision number (Fixnum).
def revision
id
end
end
class StopTimeTables < V 1.0 # :nodoc:
@ -559,6 +573,23 @@ module StopTime::Models
end
end
class CompanyInfoRevisioning < V 1.93 # :nodoc:
def self.up
add_column(CompanyInfo.table_name, :original_id, :integer)
add_column(Invoice.table_name, :company_info_id, :integer)
ci = CompanyInfo.last
Invoice.all.each do |i|
i.company_info = ci
i.save
end
end
def self.down
remove_column(CompanyInfo.table_name, :original_id)
remove_column(Invoice.table_name, :company_info_id)
end
end
end # StopTime::Models
# = The Stop… Camping Time! controllers