freshtrack 0.4.1.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.4.2 2009-08-02
2
+
3
+ * 1 tiny enhancement:
4
+ * Added invoice amount and owed amount to aging report
5
+
1
6
  == 0.4.1.1 2009-07-31
2
7
 
3
8
  * Maybe adding the invoice files to the Manifest is a good idea.
data/Manifest.txt CHANGED
@@ -32,6 +32,7 @@ spec/time_collectors/one_inch_punch_spec.rb
32
32
  spec/time_collectors/punch_spec.rb
33
33
  spec/freshbooks/base_object_spec.rb
34
34
  spec/freshbooks/invoice_spec.rb
35
+ spec/freshbooks/payment_spec.rb
35
36
  spec/freshbooks/project_spec.rb
36
37
  spec/freshbooks/task_spec.rb
37
38
  spec/freshbooks/time_entry_spec.rb
data/bin/freshtrack CHANGED
@@ -45,10 +45,10 @@ end
45
45
  if aging
46
46
  Freshtrack.init
47
47
  aging = Freshtrack.invoice_aging
48
- printf "%-10s\t%-50s\t%s\t%s\n", 'Invoice', 'Client', 'Age', 'Status'
48
+ printf "%-8s %-40s %-5s %-6s %8s %8s\n", 'Invoice', 'Client', 'Age', 'Status', 'Amount', 'Owed'
49
49
  printf "%s\n", '-' * 86
50
50
  aging.each do |inv|
51
- printf "%-10s\t%-50s\t%s\t%s\n", *inv.values_at(:number, :client, :age, :status)
51
+ printf "%-8s %-40s %-5s %-6s %8.2f %8.2f\n", *inv.values_at(:number, :client, :age, :status, :amount, :owed)
52
52
  end
53
53
  exit
54
54
  end
@@ -10,6 +10,18 @@ module FreshBooks
10
10
  Client.get(client_id)
11
11
  end
12
12
 
13
+ def payments
14
+ Payment.list('invoice_id' => invoice_id) || []
15
+ end
16
+
17
+ def paid_amount
18
+ payments.inject(0) { |sum, pay| sum + pay.amount }
19
+ end
20
+
21
+ def owed_amount
22
+ amount - paid_amount
23
+ end
24
+
13
25
  attr_accessor :number
14
26
 
15
27
  alias_method :old_brackets, :[]
@@ -2,9 +2,8 @@ module Freshtrack #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- TINY = 1
6
- FUCKUP = 1
5
+ TINY = 2
7
6
 
8
- STRING = [MAJOR, MINOR, TINY, FUCKUP].join('.')
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
9
8
  end
10
9
  end
data/lib/freshtrack.rb CHANGED
@@ -87,7 +87,9 @@ module Freshtrack
87
87
  :number => i.number,
88
88
  :client => i.client.organization,
89
89
  :age => Date.today - i.date,
90
- :status => i.status
90
+ :status => i.status,
91
+ :amount => i.amount,
92
+ :owed => i.owed_amount
91
93
  }
92
94
  end
93
95
  end
@@ -21,6 +21,10 @@ describe FreshBooks::Invoice do
21
21
  it 'should have a status' do
22
22
  @invoice.should respond_to(:status)
23
23
  end
24
+
25
+ it 'should have an amount' do
26
+ @invoice.should respond_to(:amount)
27
+ end
24
28
  end
25
29
 
26
30
  describe 'type mappings' do
@@ -35,6 +39,10 @@ describe FreshBooks::Invoice do
35
39
  it 'should map date to Date' do
36
40
  @mapping['date'].should == Date
37
41
  end
42
+
43
+ it 'should map amount to Float' do
44
+ @mapping['amount'].should == Float
45
+ end
38
46
  end
39
47
 
40
48
  it 'should indicate open status' do
@@ -80,7 +88,7 @@ describe FreshBooks::Invoice do
80
88
  @invoice.client
81
89
  end
82
90
 
83
- it 'should return found project' do
91
+ it 'should return found client' do
84
92
  client = stub('client')
85
93
  client_id = stub('client ID')
86
94
  @invoice.stubs(:client_id).returns(client_id)
@@ -133,4 +141,64 @@ describe FreshBooks::Invoice do
133
141
  @invoice.client_id = 3
134
142
  @invoice['client_id'].should == 3
135
143
  end
144
+
145
+ it 'should have payments' do
146
+ @invoice.should respond_to(:payments)
147
+ end
148
+
149
+ describe 'payments' do
150
+ before :each do
151
+ @payments = Array.new(3) { stub('payment') }
152
+ FreshBooks::Payment.stubs(:list).returns(@payments)
153
+ end
154
+
155
+ it 'should get a list from Payment' do
156
+ FreshBooks::Payment.expects(:list)
157
+ @invoice.payments
158
+ end
159
+
160
+ it 'should pass the invoice_id when getting the list' do
161
+ @invoice.invoice_id = '0000073'
162
+ FreshBooks::Payment.expects(:list).with('invoice_id' => @invoice.invoice_id)
163
+ @invoice.payments
164
+ end
165
+
166
+ it 'should return the list from Payment' do
167
+ @invoice.payments.should == @payments
168
+ end
169
+
170
+ it 'should return an empty array if Payment returns nil' do
171
+ FreshBooks::Payment.stubs(:list).returns(nil)
172
+ @invoice.payments.should == []
173
+ end
174
+ end
175
+
176
+ it 'should have a paid amount' do
177
+ @invoice.should respond_to(:paid_amount)
178
+ end
179
+
180
+ describe 'paid amount' do
181
+ it 'should be the sum of payment amounts' do
182
+ payments = [stub('payment', :amount => 3), stub('payment', :amount => 15), stub('payment', :amount => 5)]
183
+ @invoice.stubs(:payments).returns(payments)
184
+ @invoice.paid_amount.should == 23
185
+ end
186
+
187
+ it 'should be 0 if there are no payments' do
188
+ @invoice.stubs(:payments).returns([])
189
+ @invoice.paid_amount.should == 0
190
+ end
191
+ end
192
+
193
+ it 'should have an owed amount' do
194
+ @invoice.should respond_to(:owed_amount)
195
+ end
196
+
197
+ describe 'owed amount' do
198
+ it 'should be invoice amount less paid amount' do
199
+ @invoice.amount = 60
200
+ @invoice.stubs(:paid_amount).returns(50)
201
+ @invoice.owed_amount.should == 10
202
+ end
203
+ end
136
204
  end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
2
+
3
+ describe FreshBooks::Payment do
4
+ before :each do
5
+ @payment = FreshBooks::Payment.new
6
+ end
7
+
8
+ describe 'attributes' do
9
+ it 'should have an invoice_id' do
10
+ @payment.should respond_to(:invoice_id)
11
+ end
12
+
13
+ it 'should have an amount' do
14
+ @payment.should respond_to(:amount)
15
+ end
16
+ end
17
+
18
+ describe 'type mappings' do
19
+ before :each do
20
+ @mapping = FreshBooks::Payment::TYPE_MAPPINGS
21
+ end
22
+
23
+ it 'should map amount to Float' do
24
+ @mapping['amount'].should == Float
25
+ end
26
+ end
27
+ end
@@ -75,9 +75,9 @@ describe 'freshtrack command' do
75
75
  describe 'when --aging specified' do
76
76
  before :each do
77
77
  @aging_info = [
78
- { :id => 5, :number => '123', :age => 31, :client => 'blah', :status => 'viewed' },
79
- { :id => 53, :number => '234', :age => 43, :client => 'bang', :status => 'sent' },
80
- { :id => 20, :number => '938', :age => 3, :client => 'boom', :status => 'viewed' }
78
+ { :id => 5, :number => '123', :age => 31, :client => 'blah', :status => 'viewed', :amount => 123.3, :owed => 5.67 },
79
+ { :id => 53, :number => '234', :age => 43, :client => 'bang', :status => 'sent', :amount => 60.0, :owed => 60.0 },
80
+ { :id => 20, :number => '938', :age => 3, :client => 'boom', :status => 'viewed', :amount => 100.0, :owed => 100.0 }
81
81
  ]
82
82
  Freshtrack.stubs(:invoice_aging).returns(@aging_info)
83
83
  self.stubs(:printf)
@@ -134,6 +134,22 @@ describe 'freshtrack command' do
134
134
  aging_run
135
135
  end
136
136
 
137
+ it 'should print the amount of each invoice' do
138
+ pending 'making this actually test what it purports to'
139
+ @aging_info.each do |info|
140
+ self.expects(:printf) { |*args| args.include?(info[:amount]) }
141
+ end
142
+ aging_run
143
+ end
144
+
145
+ it 'should print the owed of each invoice' do
146
+ pending 'making this actually test what it purports to'
147
+ @aging_info.each do |info|
148
+ self.expects(:printf) { |*args| args.include?(info[:owed]) }
149
+ end
150
+ aging_run
151
+ end
152
+
137
153
  it 'should not track time' do
138
154
  Freshtrack.expects(:track).never
139
155
  aging_run
@@ -443,9 +443,9 @@ describe Freshtrack do
443
443
  today = Date.today
444
444
 
445
445
  @invoices = [
446
- stub('invoice', :invoice_id => '1234', :number => '4567', :client => stub('client', :organization => 'client 20'), :date => today - 3, :status => 'partial'),
447
- stub('invoice', :invoice_id => '19873', :number => '1456', :client => stub('client', :organization => 'client 3'), :date => today - 20, :status => 'viewed'),
448
- stub('invoice', :invoice_id => '0038', :number => '30267', :client => stub('client', :organization => 'client 4'), :date => today - 59, :status => 'sent')
446
+ stub('invoice', :invoice_id => '1234', :number => '4567', :client => stub('client', :organization => 'client 20'), :date => today - 3, :status => 'partial', :amount => 50, :owed_amount => 3),
447
+ stub('invoice', :invoice_id => '19873', :number => '1456', :client => stub('client', :organization => 'client 3'), :date => today - 20, :status => 'viewed', :amount => 60, :owed_amount => 60),
448
+ stub('invoice', :invoice_id => '0038', :number => '30267', :client => stub('client', :organization => 'client 4'), :date => today - 59, :status => 'sent', :amount => 20, :owed_amount => 20)
449
449
  ]
450
450
  Freshtrack.stubs(:open_invoices).returns(@invoices)
451
451
  end
@@ -479,6 +479,16 @@ describe Freshtrack do
479
479
  Freshtrack.invoice_aging.collect { |i| i[:status] }.should == statuses
480
480
  end
481
481
 
482
+ it 'should extract the amount for each open invoice' do
483
+ amounts = @invoices.collect { |i| i.amount }
484
+ Freshtrack.invoice_aging.collect { |i| i[:amount] }.should == amounts
485
+ end
486
+
487
+ it 'should extract the owed amount for each open invoice' do
488
+ oweds = @invoices.collect { |i| i.owed_amount }
489
+ Freshtrack.invoice_aging.collect { |i| i[:owed] }.should == oweds
490
+ end
491
+
482
492
  it 'should return an empty array if there are no open invoices' do
483
493
  Freshtrack.stubs(:open_invoices).returns([])
484
494
  Freshtrack.invoice_aging.should == []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freshtrack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yossef Mendelssohn
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-31 00:00:00 -05:00
12
+ date: 2009-08-02 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -98,6 +98,7 @@ files:
98
98
  - spec/time_collectors/punch_spec.rb
99
99
  - spec/freshbooks/base_object_spec.rb
100
100
  - spec/freshbooks/invoice_spec.rb
101
+ - spec/freshbooks/payment_spec.rb
101
102
  - spec/freshbooks/project_spec.rb
102
103
  - spec/freshbooks/task_spec.rb
103
104
  - spec/freshbooks/time_entry_spec.rb