xeroizer 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.4.4
@@ -16,6 +16,7 @@ module Xeroizer
16
16
 
17
17
  set_primary_key :contact_id
18
18
  set_possible_primary_keys :contact_id, :contact_number
19
+ list_contains_summary_only true
19
20
 
20
21
  guid :contact_id
21
22
  string :contact_number
@@ -28,14 +29,15 @@ module Xeroizer
28
29
  string :first_name
29
30
  string :last_name
30
31
  string :email_address
32
+ string :skype_user_name
31
33
  string :contact_groups
32
34
  string :default_currency
33
35
  datetime :updated_date_utc, :api_name => 'UpdatedDateUTC'
34
36
  boolean :is_supplier
35
37
  boolean :is_customer
36
38
 
37
- has_many :addresses
38
- has_many :phones
39
+ has_many :addresses, :list_complete => true
40
+ has_many :phones, :list_complete => true
39
41
  has_many :contact_groups
40
42
 
41
43
  validates_presence_of :name
@@ -70,14 +70,26 @@ module Xeroizer
70
70
 
71
71
  public
72
72
 
73
+ # Access the contact name without forcing a download of
74
+ # an incomplete, summary credit note.
75
+ def contact_name
76
+ attributes[:contact] && attributes[:contact][:name]
77
+ end
78
+
79
+ # Access the contact ID without forcing a download of an
80
+ # incomplete, summary credit note.
81
+ def contact_id
82
+ attributes[:contact] && attributes[:contact][:contact_id]
83
+ end
84
+
73
85
  # Swallow assignment of attributes that should only be calculated automatically.
74
86
  def sub_total=(value); raise SettingTotalDirectlyNotSupported.new(:sub_total); end
75
87
  def total_tax=(value); raise SettingTotalDirectlyNotSupported.new(:total_tax); end
76
88
  def total=(value); raise SettingTotalDirectlyNotSupported.new(:total); end
77
89
 
78
90
  # Calculate sub_total from line_items.
79
- def sub_total
80
- if new_record? || complete_record_downloaded?
91
+ def sub_total(always_summary = false)
92
+ if !always_summary && (new_record? || (!new_record? && line_items && line_items.size > 0))
81
93
  sum = (line_items || []).inject(BigDecimal.new('0')) { | sum, line_item | sum + line_item.line_amount }
82
94
 
83
95
  # If the default amount types are inclusive of 'tax' then remove the tax amount from this sub-total.
@@ -87,19 +99,23 @@ module Xeroizer
87
99
  attributes[:sub_total]
88
100
  end
89
101
  end
90
-
102
+
91
103
  # Calculate total_tax from line_items.
92
- def total_tax
93
- if new_record? || complete_record_downloaded?
104
+ def total_tax(always_summary = false)
105
+ if !always_summary && (new_record? || (!new_record? && line_items && line_items.size > 0))
94
106
  (line_items || []).inject(BigDecimal.new('0')) { | sum, line_item | sum + line_item.tax_amount }
95
107
  else
96
108
  attributes[:total_tax]
97
109
  end
98
110
  end
99
-
111
+
100
112
  # Calculate the total from line_items.
101
- def total
102
- sub_total + total_tax
113
+ def total(always_summary = false)
114
+ unless always_summary
115
+ sub_total + total_tax
116
+ else
117
+ attributes[:total]
118
+ end
103
119
  end
104
120
 
105
121
  # Retrieve the PDF version of this credit note.
@@ -113,8 +113,8 @@ module Xeroizer
113
113
  def total=(value); raise SettingTotalDirectlyNotSupported.new(:total); end
114
114
 
115
115
  # Calculate sub_total from line_items.
116
- def sub_total
117
- if new_record? || (!new_record? && line_items && line_items.size > 0)
116
+ def sub_total(always_summary = false)
117
+ if !always_summary && (new_record? || (!new_record? && line_items && line_items.size > 0))
118
118
  sum = (line_items || []).inject(BigDecimal.new('0')) { | sum, line_item | sum + line_item.line_amount }
119
119
 
120
120
  # If the default amount types are inclusive of 'tax' then remove the tax amount from this sub-total.
@@ -126,8 +126,8 @@ module Xeroizer
126
126
  end
127
127
 
128
128
  # Calculate total_tax from line_items.
129
- def total_tax
130
- if new_record? || (!new_record? && line_items && line_items.size > 0)
129
+ def total_tax(always_summary = false)
130
+ if !always_summary && (new_record? || (!new_record? && line_items && line_items.size > 0))
131
131
  (line_items || []).inject(BigDecimal.new('0')) { | sum, line_item | sum + line_item.tax_amount }
132
132
  else
133
133
  attributes[:total_tax]
@@ -135,8 +135,12 @@ module Xeroizer
135
135
  end
136
136
 
137
137
  # Calculate the total from line_items.
138
- def total
139
- sub_total + total_tax
138
+ def total(always_summary = false)
139
+ unless always_summary
140
+ sub_total + total_tax
141
+ else
142
+ attributes[:total]
143
+ end
140
144
  end
141
145
 
142
146
  # Retrieve the PDF version of this invoice.
@@ -26,7 +26,9 @@ module Xeroizer
26
26
 
27
27
  # Calculate the line_total (if there is a quantity and unit_amount).
28
28
  # Description-only lines have been allowed since Xero V2.09.
29
- def line_amount
29
+ def line_amount(summary_only = false)
30
+ return attributes[:line_amount] if summary_only
31
+
30
32
  BigDecimal((quantity * unit_amount).to_s).round(2) if quantity && unit_amount
31
33
  end
32
34
 
@@ -10,16 +10,21 @@ module Xeroizer
10
10
 
11
11
  class Organisation < Base
12
12
 
13
+ string :api_key, :api_name => 'APIKey'
13
14
  string :name
14
15
  string :legal_name
15
16
  boolean :pays_tax
16
17
  string :version
17
18
  string :organisation_type
18
19
  string :base_currency
20
+ string :country_code
21
+ boolean :is_demo_company
22
+ string :organisation_status
19
23
  integer :financial_year_end_day
20
24
  integer :financial_year_end_month
21
25
  date :period_lock_date
22
26
  date :end_of_year_lock_date
27
+ string :tax_number
23
28
  string :registration_number
24
29
  datetime :created_date_utc, :api_name => 'CreatedDateUTC'
25
30
 
@@ -16,11 +16,26 @@ module Xeroizer
16
16
  date :date
17
17
  decimal :amount
18
18
  decimal :currency_rate
19
+ string :payment_type
20
+ string :status
19
21
  string :reference
20
-
22
+ datetime :updated_date_utc, :api_name => 'UpdatedDateUTC'
23
+
21
24
  belongs_to :account
22
25
  belongs_to :invoice
23
26
 
27
+ def invoice_id
28
+ invoice.id if invoice
29
+ end
30
+
31
+ def account_id
32
+ account.id if account
33
+ end
34
+
35
+ def account_code
36
+ account.code if account
37
+ end
38
+
24
39
  end
25
40
 
26
41
  end
@@ -125,7 +125,7 @@ module Xeroizer
125
125
  # the complete version of the record before accessing the association.
126
126
  if list_contains_summary_only?
127
127
  define_method internal_field_name do
128
- download_complete_record! unless new_record? || complete_record_downloaded?
128
+ download_complete_record! unless new_record? || options[:list_complete] || complete_record_downloaded?
129
129
  self.attributes[field_name] || ((association_type == :has_many) ? [] : nil)
130
130
  end
131
131
  end
data/xeroizer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "xeroizer"
8
- s.version = "0.4.3"
8
+ s.version = "0.4.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wayne Robinson"]
12
- s.date = "2012-04-09"
12
+ s.date = "2012-04-16"
13
13
  s.description = "Ruby library for the Xero accounting system API."
14
14
  s.email = "wayne.robinson@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xeroizer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 3
10
- version: 0.4.3
9
+ - 4
10
+ version: 0.4.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Wayne Robinson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-09 00:00:00 Z
18
+ date: 2012-04-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  prerelease: false