Class: Economic::Invoice

Inherits:
Base
  • Object
show all
Defined in:
lib/economic/invoice.rb

Class Method Summary collapse

Methods inherited from Base

add_attribute, add_relation, #dirty?, field, #initialize, low_camel_case, #model_class, relation, #repo, snake_case, #to_h, #values_based_on_hash

Constructor Details

This class inherits a constructor from Economic::Base

Class Method Details

.build_from_soap_api(data) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/economic/invoice.rb', line 31

def self.build_from_soap_api(data)
  # TODO: Add all the options
  hash = {
    "currency" => data[:currency_handle][:code],
    "date" => data[:date].to_date,
    "dueDate" => data[:due_date].to_date,
    "exchangeRate" => data[:exchange_rate],
    "grossAmount" => data[:gross_amount],
    # where is grossAmountInBaseCurrency?
    "lines" => repo.find_lines(data[:handle][:id]),
    "marginInBaseCurrency" => data[:margin],
    "marginPercentage" => data[:margin_as_percent],
    "netAmount" => data[:net_amount],
    "roundingAmount" => data[:rounding_amount],
    "vatAmount" => data[:vat_amount],
    "draftInvoiceNumber" => data[:handle][:id], # TODO: What about id?
    "customer" => {"customerNumber" => data[:debtor_handle][:id].to_i},
    "layout" => {"layoutNumber" => data[:layout_handle][:id].to_i},
    "paymentTerms" => {"paymentTermsNumber" => data[:term_of_payment_handle][:id].to_i},
    "references" => {"other" => data[:other_reference]},
  }

  new(hash)
end

.repoObject



56
57
58
# File 'lib/economic/invoice.rb', line 56

def self.repo
  Economic::Invoices::DraftsRepo
end