Class: InvoicesWithTotal

Inherits:
Invoice
  • Object
show all
Defined in:
app/model_views/invoices_with_total.rb

Constant Summary

Constants inherited from Invoice

Invoice::ACTIVITY_TOTAL_SQL

Instance Method Summary collapse

Methods inherited from Invoice

#amount, #amount_outstanding, #amount_paid, #authorized_for?, #ensure_not_published_on_destroy, #ensure_not_published_on_update, find_with_totals, #initialize, #invalid_if_published, #is_most_recent_invoice?, #is_paid?, #long_name, #name, #paid_on, #recommended_activities, recommended_activities_for, #sub_total, #taxes_total, #validate_invoice_payments_not_greater_than_amount, #validate_on_update, #validate_payment_assignments_only_if_published

Methods included from ExtensibleObjectHelper

append_features

Constructor Details

This class inherits a constructor from Invoice

Instance Method Details

#create(*args) ⇒ Object



9
10
11
# File 'app/model_views/invoices_with_total.rb', line 9

def create(*args)    
  invoice_assign_and_save! Invoice.new
end

#destroyObject



17
18
19
20
# File 'app/model_views/invoices_with_total.rb', line 17

def destroy
  inv = Invoice.find(id)
  inv.destroy
end

#invoice_assign_and_save!(inv) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/model_views/invoices_with_total.rb', line 22

def invoice_assign_and_save!(inv)
  invoice_columns = Invoice.columns.collect{|c| c.name}-['id']

  inv.activity_ids = activity_ids
  inv.payment_assignments = payment_assignments
  inv.activity_type_ids = activity_type_ids
  
  attributes.reject{|k,v| true unless invoice_columns.include? k }.each{ |k,v| inv.send "#{k}=", v }

  inv.save!

  # For the case of a create! this assign the id to the current view
  self.id ||= inv.id

  inv.errors.each { |attr,msg| errors.add attr, msg }
  
  inv
end

#updateObject



13
14
15
# File 'app/model_views/invoices_with_total.rb', line 13

def update
  invoice_assign_and_save! Invoice.find(id)
end