xeroizer 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
@@ -106,5 +106,24 @@ module Xeroizer
106
106
  end
107
107
 
108
108
  end
109
+
110
+ class CannotChangeInvoiceStatus < StandardError
111
+
112
+ def initialize(invoice, new_status)
113
+ @invoice = invoice
114
+ @new_status = new_status
115
+ end
116
+
117
+ def message
118
+ case new_status
119
+ when 'DELETED', 'VOIDED'
120
+ unless @invoice.payments.size == 0
121
+ "There must be no payments in this invoice to change to '#{@new_status}'"
122
+ end
123
+
124
+ end
125
+ end
126
+
127
+ end
109
128
 
110
129
  end
@@ -133,8 +133,26 @@ module Xeroizer
133
133
  def pdf(filename = nil)
134
134
  parent.pdf(id, filename)
135
135
  end
136
+
137
+ # Delete an approved invoice with no payments.
138
+ def delete!
139
+ delete_or_void_invoice!('DELETED')
140
+ end
141
+
142
+ # Void an approved invoice with no payments.
143
+ def void!
144
+ delete_or_void_invoice!('VOIDED')
145
+ end
146
+
147
+ protected
148
+
149
+ def delete_or_void_authorised_invoice!(new_status)
150
+ raise CannotChangeInvoiceStatus.new(record, new_status) unless self.payments.size == 0
151
+ self.status = new_status
152
+ self.save
153
+ end
136
154
 
137
155
  end
138
156
 
139
157
  end
140
- end
158
+ end
@@ -32,12 +32,15 @@ module Xeroizer
32
32
  # Swallow assignment of attributes that should only be calculated automatically.
33
33
  def line_amount=(value); raise SettingTotalDirectlyNotSupported.new(:line_amount); end
34
34
 
35
- # Calculate the line_total.
35
+ # Calculate the line_total (if there is a quantity and unit_amount).
36
+ # Description-only lines have been allowed since Xero V2.09.
36
37
  def line_amount
37
- quantity * unit_amount
38
+ unless quantity.nil? && unit_amount.nil?
39
+ quantity * unit_amount
40
+ end
38
41
  end
39
42
 
40
43
  end
41
44
 
42
45
  end
43
- end
46
+ end
data/xeroizer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{xeroizer}
8
- s.version = "0.3.2"
8
+ s.version = "0.3.3"
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 = %q{2011-06-09}
12
+ s.date = %q{2011-06-14}
13
13
  s.description = %q{Ruby library for the Xero accounting system API.}
14
14
  s.email = %q{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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 2
10
- version: 0.3.2
9
+ - 3
10
+ version: 0.3.3
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: 2011-06-09 00:00:00 +10:00
18
+ date: 2011-06-14 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency