invoicing 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -0
  3. data/README.md +57 -0
  4. data/Rakefile +16 -37
  5. data/lib/invoicing.rb +20 -10
  6. data/lib/invoicing/cached_record.rb +9 -6
  7. data/lib/invoicing/class_info.rb +34 -34
  8. data/lib/invoicing/connection_adapter_ext.rb +4 -4
  9. data/lib/invoicing/countries/uk.rb +6 -6
  10. data/lib/invoicing/currency_value.rb +39 -32
  11. data/lib/invoicing/find_subclasses.rb +40 -15
  12. data/lib/invoicing/ledger_item.rb +166 -145
  13. data/lib/invoicing/ledger_item/pdf_generator.rb +108 -0
  14. data/lib/invoicing/ledger_item/render_html.rb +76 -73
  15. data/lib/invoicing/ledger_item/render_ubl.rb +37 -35
  16. data/lib/invoicing/line_item.rb +43 -38
  17. data/lib/invoicing/price.rb +1 -1
  18. data/lib/invoicing/tax_rate.rb +3 -6
  19. data/lib/invoicing/taxable.rb +37 -32
  20. data/lib/invoicing/time_dependent.rb +40 -40
  21. data/lib/invoicing/version.rb +4 -4
  22. data/lib/rails/generators/invoicing/invoicing_generator.rb +14 -0
  23. data/lib/rails/generators/invoicing/ledger_item/ledger_item_generator.rb +17 -0
  24. data/lib/rails/generators/invoicing/ledger_item/templates/migration.rb +25 -0
  25. data/lib/rails/generators/invoicing/ledger_item/templates/model.rb +5 -0
  26. data/lib/rails/generators/invoicing/line_item/line_item_generator.rb +17 -0
  27. data/lib/rails/generators/invoicing/line_item/templates/migration.rb +20 -0
  28. data/lib/rails/generators/invoicing/line_item/templates/model.rb +5 -0
  29. data/lib/rails/generators/invoicing/tax_rate/tax_rate_generator.rb +17 -0
  30. data/lib/rails/generators/invoicing/tax_rate/templates/migration.rb +14 -0
  31. data/lib/rails/generators/invoicing/tax_rate/templates/model.rb +3 -0
  32. metadata +110 -153
  33. data.tar.gz.sig +0 -1
  34. data/History.txt +0 -31
  35. data/Manifest.txt +0 -62
  36. data/PostInstall.txt +0 -10
  37. data/README.rdoc +0 -58
  38. data/script/console +0 -10
  39. data/script/destroy +0 -14
  40. data/script/generate +0 -14
  41. data/tasks/rcov.rake +0 -4
  42. data/test/cached_record_test.rb +0 -100
  43. data/test/class_info_test.rb +0 -253
  44. data/test/connection_adapter_ext_test.rb +0 -79
  45. data/test/currency_value_test.rb +0 -209
  46. data/test/find_subclasses_test.rb +0 -120
  47. data/test/fixtures/README +0 -7
  48. data/test/fixtures/cached_record.sql +0 -22
  49. data/test/fixtures/class_info.sql +0 -28
  50. data/test/fixtures/currency_value.sql +0 -29
  51. data/test/fixtures/find_subclasses.sql +0 -43
  52. data/test/fixtures/ledger_item.sql +0 -39
  53. data/test/fixtures/line_item.sql +0 -33
  54. data/test/fixtures/price.sql +0 -4
  55. data/test/fixtures/tax_rate.sql +0 -4
  56. data/test/fixtures/taxable.sql +0 -14
  57. data/test/fixtures/time_dependent.sql +0 -35
  58. data/test/ledger_item_test.rb +0 -444
  59. data/test/line_item_test.rb +0 -139
  60. data/test/models/README +0 -4
  61. data/test/models/test_subclass_in_another_file.rb +0 -3
  62. data/test/models/test_subclass_not_in_database.rb +0 -6
  63. data/test/price_test.rb +0 -9
  64. data/test/ref-output/creditnote3.html +0 -82
  65. data/test/ref-output/creditnote3.xml +0 -89
  66. data/test/ref-output/invoice1.html +0 -93
  67. data/test/ref-output/invoice1.xml +0 -111
  68. data/test/ref-output/invoice2.html +0 -86
  69. data/test/ref-output/invoice2.xml +0 -98
  70. data/test/ref-output/invoice_null.html +0 -36
  71. data/test/render_html_test.rb +0 -70
  72. data/test/render_ubl_test.rb +0 -44
  73. data/test/setup.rb +0 -37
  74. data/test/tax_rate_test.rb +0 -9
  75. data/test/taxable_test.rb +0 -180
  76. data/test/test_helper.rb +0 -72
  77. data/test/time_dependent_test.rb +0 -180
  78. metadata.gz.sig +0 -4
@@ -1,72 +0,0 @@
1
- require 'test/unit'
2
- require 'rubygems'
3
- require 'activerecord'
4
- require 'activesupport'
5
- require 'flexmock/test_unit'
6
-
7
- $: << File.join(File.dirname(__FILE__), '..', 'lib')
8
-
9
- ActiveSupport::Dependencies.load_paths << File.join(File.dirname(__FILE__), 'models')
10
-
11
- require 'invoicing'
12
-
13
- # Overridden by ../../config/database.yml if it exists.
14
- TEST_DB_CONFIG = {
15
- :postgresql => {:adapter => "postgresql", :host => "localhost", :database => "invoicing_test",
16
- :username => "invoicing", :password => "password"},
17
- :mysql => {:adapter => "mysql", :host => "localhost", :database => "invoicing_test",
18
- :username => "root", :password => ""}
19
- }
20
- TEST_DB_CONFIG_FILE = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'database.yml'))
21
-
22
- def database_used_for_testing
23
- (ENV['DATABASE'] || :mysql).to_sym
24
- end
25
-
26
- def test_in_all_databases
27
- !!ENV['TEST_ALL_DATABASES']
28
- end
29
-
30
- def connect_to_testing_database
31
- db_config = TEST_DB_CONFIG[database_used_for_testing]
32
- db_config_from_file = false
33
-
34
- if File.exists? TEST_DB_CONFIG_FILE
35
- yaml = YAML::load File.open(TEST_DB_CONFIG_FILE)
36
- if yaml && yaml['test'] && (yaml['test']['adapter'].to_s == database_used_for_testing.to_s)
37
- db_config = yaml['test']
38
- db_config_from_file = true
39
- end
40
- end
41
-
42
- puts "Connecting to #{database_used_for_testing} with config #{db_config.inspect}" +
43
- (db_config_from_file ? " from #{TEST_DB_CONFIG_FILE}" : "")
44
- ActiveRecord::Base.establish_connection(db_config)
45
- end
46
-
47
- connect_to_testing_database
48
-
49
- require 'setup'
50
-
51
-
52
- ENV['TZ'] = 'Etc/UTC' # timezone of values in database
53
- ActiveRecord::Base.default_timezone = :utc # timezone of created_at and updated_at
54
- Time.zone = 'Etc/UTC' # timezone for output (when using Time#in_time_zone)
55
-
56
-
57
- # Behave a bit like ActiveRecord's transactional fixtures.
58
- module Test
59
- module Unit
60
- class TestCase
61
- def setup
62
- ActiveRecord::Base.connection.increment_open_transactions
63
- ActiveRecord::Base.connection.begin_db_transaction
64
- end
65
-
66
- def teardown
67
- ActiveRecord::Base.connection.rollback_db_transaction
68
- ActiveRecord::Base.connection.decrement_open_transactions
69
- end
70
- end
71
- end
72
- end
@@ -1,180 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
-
3
- class CachedRecordTest < Test::Unit::TestCase
4
-
5
- class TimeDependentRecord < ActiveRecord::Base
6
- # All columns are renamed to test renaming
7
- set_primary_key 'id2'
8
- acts_as_time_dependent :id => 'id2', :valid_from => 'valid_from2', :valid_until => 'valid_until2',
9
- :replaced_by_id => 'replaced_by_id2', :value => 'value2', :is_default => 'is_default2'
10
- end
11
-
12
-
13
- def test_valid_records_during_single_period
14
- records = TimeDependentRecord.valid_records_during(DateTime.parse('2009-01-01'), DateTime.parse('2009-03-01'))
15
- assert_equal [3, 6, 8, 10], records.map{|r| r.id2}.sort
16
- end
17
-
18
- def test_valid_records_during_single_period_ending_on_change_date
19
- records = TimeDependentRecord.valid_records_during(DateTime.parse('2008-10-31'), DateTime.parse('2009-01-01'))
20
- assert_equal [1, 2, 5, 8, 10], records.map{|r| r.id2}.sort
21
- end
22
-
23
- def test_valid_records_during_transition_period
24
- records = TimeDependentRecord.valid_records_during(DateTime.parse('2008-09-01'), DateTime.parse('2009-02-28'))
25
- assert_equal [1, 2, 5, 6, 8, 10], records.map{|r| r.id2}.sort
26
- end
27
-
28
- def test_valid_records_during_period_after_unreplaced_expiry
29
- records = TimeDependentRecord.valid_records_during(DateTime.parse('2011-09-01'), DateTime.parse('2011-09-02'))
30
- assert_equal [4, 9, 10], records.map{|r| r.id2}.sort
31
- end
32
-
33
- def test_valid_records_at_boundary
34
- records = TimeDependentRecord.valid_records_at(DateTime.parse('2010-01-01'))
35
- assert_equal [4, 7, 8, 10], records.map{|r| r.id2}.sort
36
- end
37
-
38
- def test_valid_records_at_middle_of_period
39
- records = TimeDependentRecord.valid_records_at(DateTime.parse('2009-07-01'))
40
- assert_equal [3, 6, 8, 10], records.map{|r| r.id2}.sort
41
- end
42
-
43
- def test_valid_records_at_just_before_end_of_period
44
- records = TimeDependentRecord.valid_records_at(DateTime.parse('2008-12-31 23:59:59'))
45
- assert_equal [1, 2, 5, 8, 10], records.map{|r| r.id2}.sort
46
- end
47
-
48
- def test_default_record_at_returns_default
49
- assert_equal 9, TimeDependentRecord.default_record_at(DateTime.parse('2011-04-01')).id2
50
- end
51
-
52
- def test_default_record_at_where_there_is_no_default
53
- assert_nil TimeDependentRecord.default_record_at(DateTime.parse('2008-03-01'))
54
- end
55
-
56
- def test_default_value_at
57
- assert_equal 'Seven', TimeDependentRecord.default_value_at(DateTime.parse('2010-01-01 00:00:01'))
58
- end
59
-
60
- def test_default_value_at_alias
61
- assert_equal 'Six', TimeDependentRecord.default_value2_at(DateTime.parse('2009-12-31 23:59:59'))
62
- end
63
-
64
- def test_default_record_now
65
- # Hello future. This is January 2009 speaking. Is someone out there still using this library?
66
- # If so, you may want to update this test from time to time. But you probably won't need to.
67
- expected = case Date.today.year
68
- when 2009 then 6
69
- when 2010 then 7
70
- else 9
71
- end
72
- assert_equal expected, TimeDependentRecord.default_record_now.id2
73
- end
74
-
75
- def test_default_value_now
76
- expected = case Date.today.year
77
- when 2009 then 'Six'
78
- when 2010 then 'Seven'
79
- else 'Nine'
80
- end
81
- assert_equal expected, TimeDependentRecord.default_value_now
82
- end
83
-
84
- def test_default_value_now_alias
85
- expected = case Date.today.year
86
- when 2009 then 'Six'
87
- when 2010 then 'Seven'
88
- else 'Nine'
89
- end
90
- assert_equal expected, TimeDependentRecord.default_value2_now
91
- end
92
-
93
- def test_multiple_predecessors
94
- assert_equal [2, 5], TimeDependentRecord.find(3).predecessors.map{|r| r.id2}.sort
95
- end
96
-
97
- def test_one_predecessor
98
- assert_equal [8], TimeDependentRecord.find(9).predecessors.map{|r| r.id2}
99
- end
100
-
101
- def test_no_predecessors
102
- assert_equal [], TimeDependentRecord.find(1).predecessors
103
- end
104
-
105
- def test_record_at_same_period
106
- assert_equal 3, TimeDependentRecord.find(3).record_at(DateTime.parse('2009-12-31 23:59:59')).id2
107
- end
108
-
109
- def test_record_at_next_period
110
- assert_equal 4, TimeDependentRecord.find(3).record_at(DateTime.parse('2010-01-01 00:00:00')).id2
111
- end
112
-
113
- def test_record_at_future_period
114
- assert_equal 4, TimeDependentRecord.find(2).record_at(DateTime.parse('2036-07-09')).id2
115
- end
116
-
117
- def test_record_at_within_long_period
118
- assert_equal 8, TimeDependentRecord.find(8).record_at(DateTime.parse('2010-12-31 23:59:58')).id2
119
- end
120
-
121
- def test_record_at_with_no_replacement
122
- assert_nil TimeDependentRecord.find(1).record_at(DateTime.parse('2009-07-09'))
123
- end
124
-
125
- def test_record_at_with_no_predecessor
126
- assert_nil TimeDependentRecord.find(7).record_at(DateTime.parse('2008-07-09'))
127
- end
128
-
129
- def test_record_at_with_unique_predecessor
130
- assert_equal 3, TimeDependentRecord.find(4).record_at(DateTime.parse('2009-01-01')).id2
131
- end
132
-
133
- def test_record_at_with_ambiguous_predecessor
134
- assert_nil TimeDependentRecord.find(4).record_at(DateTime.parse('2008-12-31'))
135
- end
136
-
137
- def test_record_at_long_ago
138
- assert_nil TimeDependentRecord.find(10).record_at(DateTime.parse('1970-01-01'))
139
- end
140
-
141
- def test_record_now
142
- assert_equal 10, TimeDependentRecord.find(10).record_now.id2
143
- end
144
-
145
- def test_value_at
146
- assert_equal 'Four', TimeDependentRecord.find(5).value_at(DateTime.parse('2028-01-13'))
147
- end
148
-
149
- def test_value_at_alias
150
- assert_equal 'Four', TimeDependentRecord.find(5).value2_at(DateTime.parse('2028-01-13'))
151
- end
152
-
153
- def test_value_now
154
- assert_equal 'Ten', TimeDependentRecord.find(10).value_now
155
- end
156
-
157
- def test_value_now_alias
158
- assert_equal 'Ten', TimeDependentRecord.find(10).value2_now
159
- end
160
-
161
- def test_changes_until_without_changes
162
- assert_equal [], TimeDependentRecord.find(8).changes_until(DateTime.parse('2010-12-31 23:59:59'))
163
- end
164
-
165
- def test_changes_until_with_one_change
166
- assert_equal [9], TimeDependentRecord.find(8).changes_until(DateTime.parse('2011-01-01')).map{|r| r.id2}
167
- end
168
-
169
- def test_changes_until_with_multiple_changes
170
- assert_equal [3, 4], TimeDependentRecord.find(2).changes_until(DateTime.parse('2034-01-01')).map{|r| r.id2}
171
- end
172
-
173
- def test_changes_until_with_imminent_expiry
174
- assert_equal [nil], TimeDependentRecord.find(1).changes_until(DateTime.parse('2009-01-01'))
175
- end
176
-
177
- def test_changes_until_with_future_expiry
178
- assert_equal [TimeDependentRecord.find(7), nil], TimeDependentRecord.find(6).changes_until(DateTime.parse('2012-01-01'))
179
- end
180
- end
metadata.gz.sig DELETED
@@ -1,4 +0,0 @@
1
- �9V��g贵��QV�
2
- Ĺ���!�2ګ��iw���X��"�NBz�#��P��m�r%����iJ��e0wA���|��j���+=X.��v����_��%��bà
3
- �MQ�����/����e��ْ�NQ�6[�m��5vc��$0�
4
- Te�kX{%v���Җ|��P3� �–������(��oTYE�dg��و��ќK�7��h-HB� �ZH,ư��c����&Wx����5A���A�t7i}���