billing 0.0.3 → 0.0.4a

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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/billing/account.rb +84 -6
  3. data/app/models/billing/charge.rb +15 -0
  4. data/app/models/billing/department.rb +5 -0
  5. data/app/models/billing/modifier.rb +3 -1
  6. data/app/models/billing/operator.rb +4 -0
  7. data/app/models/billing/origin.rb +13 -0
  8. data/app/models/billing/payment.rb +49 -20
  9. data/app/models/billing/payment_external.rb +8 -0
  10. data/app/models/billing/payment_type.rb +3 -1
  11. data/app/models/billing/payment_type_fiscal_driver_mapping.rb +7 -0
  12. data/app/models/billing/payment_with_type.rb +18 -2
  13. data/app/models/billing/paypal_express.rb +7 -0
  14. data/app/models/billing/report.rb +66 -0
  15. data/app/models/billing/version.rb +5 -0
  16. data/app/models/{billing → concerns/billing}/account_item.rb +5 -2
  17. data/config/initializers/paper_trail.rb +3 -0
  18. data/db/migrate/20140721172932_create_billing_operators.rb +11 -0
  19. data/db/migrate/20140721173106_create_billing_departments.rb +12 -0
  20. data/db/migrate/20140722160242_change_table_base_billing_tax_group.rb +12 -0
  21. data/db/migrate/20140722160258_change_table_base_billing_operator.rb +9 -0
  22. data/db/migrate/20140722160529_change_table_base_billing_payment_type.rb +10 -0
  23. data/db/migrate/20140722160902_change_table_base_billing_departments.rb +10 -0
  24. data/db/migrate/20140722161743_change_table_base_billing_plus.rb +15 -0
  25. data/db/migrate/20140722162315_change_table_base_billing_origins.rb +13 -0
  26. data/db/migrate/20140724173527_add_origin_to_billing_account.rb +7 -0
  27. data/db/migrate/20140724173917_remove_origin_and_fiscal_defice_from_billing_payment.rb +6 -0
  28. data/db/migrate/20140725122914_add_status_to_billing_payment.rb +5 -0
  29. data/db/migrate/20140725142525_eqalize_schemas_billing_charge.rb +16 -0
  30. data/db/migrate/20140725143734_eqalize_schemas_billing_department.rb +5 -0
  31. data/db/migrate/20140725145640_eqalize_schemas_billing_closure.rb +25 -0
  32. data/db/migrate/20140725145953_eqalize_schemas_billing_operators.rb +5 -0
  33. data/db/migrate/20140725150329_eqalize_schemas_billing_origin.rb +5 -0
  34. data/db/migrate/20140725151522_eqalize_schemas_billing_payment_type.rb +8 -0
  35. data/db/migrate/20140725152125_eqalize_schemas_billing_payment.rb +14 -0
  36. data/db/migrate/20140725153215_eqalize_schemas_billing_version.rb +16 -0
  37. data/db/migrate/20140725153658_eqalize_schemas_billing_pt_fp_mapping.rb +14 -0
  38. data/db/migrate/20140725164847_add_extface_job_to_billing_account.rb +5 -0
  39. data/db/migrate/20140726163220_rename_closure_to_billing_report.rb +5 -0
  40. data/db/migrate/20140726165718_remove_closure_from_billing_account.rb +6 -0
  41. data/db/migrate/20140726170002_add_report_to_billing_account.rb +5 -0
  42. data/db/migrate/20140728110230_add_autofin_and_finalized_at_to_billing_account.rb +6 -0
  43. data/db/migrate/20140729083050_add_name_to_billing_account.rb +5 -0
  44. data/db/migrate/20140729083408_add_number_to_billing_account.rb +5 -0
  45. data/db/migrate/20140729180849_add_deleted_at_to_billing_modifier.rb +5 -0
  46. data/db/migrate/20140729182146_add_deleted_at_to_billing_account.rb +5 -0
  47. data/lib/billing/billable.rb +6 -2
  48. data/lib/billing/engine.rb +1 -0
  49. data/lib/billing/version.rb +1 -1
  50. data/test/dummy/db/development.sqlite3 +0 -0
  51. data/test/dummy/db/schema.rb +139 -1
  52. data/test/dummy/db/test.sqlite3 +0 -0
  53. data/test/dummy/log/development.log +5698 -0
  54. data/test/dummy/log/test.log +63958 -0
  55. data/test/dummy/tmp/cache/assets/test/sprockets/0cab887466527f5353fd43adab72769b +0 -0
  56. data/test/dummy/tmp/cache/assets/test/sprockets/79316f9f3f5ebcec9b368d92d2e97e23 +0 -0
  57. data/test/dummy/tmp/cache/assets/test/sprockets/d3ab844c61f1c211ed5fad5407cd18ef +0 -0
  58. data/test/fixtures/billing/accounts.yml +2 -0
  59. data/test/fixtures/billing/departments.yml +11 -0
  60. data/test/fixtures/billing/modifiers.yml +1 -0
  61. data/test/fixtures/billing/operators.yml +11 -0
  62. data/test/fixtures/billing/origins.yml +2 -0
  63. data/test/fixtures/billing/payment_types.yml +16 -0
  64. data/test/fixtures/billing/payments.yml +5 -1
  65. data/test/models/billing/account_test.rb +19 -6
  66. data/test/models/billing/department_test.rb +9 -0
  67. data/test/models/billing/modifier_test.rb +13 -0
  68. data/test/models/billing/operator_test.rb +9 -0
  69. data/test/models/billing/payment_test.rb +25 -0
  70. metadata +64 -6
  71. data/app/assets/javascripts/billing/payments.js +0 -2
@@ -6,6 +6,8 @@
6
6
  #
7
7
  one:
8
8
  billable: one(Profile)
9
+ origin: one
9
10
 
10
11
  two:
11
12
  billable: one(Profile)
13
+ origin:
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ name: Group1
5
+ tax_group: one
6
+ type:
7
+
8
+ two:
9
+ name: Group2
10
+ tax_group: two
11
+ type:
@@ -10,5 +10,6 @@ one:
10
10
 
11
11
  two:
12
12
  account: one
13
+ charge: one
13
14
  fixed_value_cents: 100
14
15
  fixed_value_currency: 'USD'
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ master_id: 1
5
+ name: MyString
6
+ type:
7
+
8
+ two:
9
+ master_id: 1
10
+ name: MyString
11
+ type:
@@ -2,6 +2,8 @@
2
2
 
3
3
  one:
4
4
  name: MyString
5
+ payment_model: Billing::PaymentWithType
5
6
 
6
7
  two:
7
8
  name: MyString
9
+ payment_model: Billing::PaymentWithType
@@ -9,3 +9,19 @@ two:
9
9
  name: MyString
10
10
  cash: false
11
11
  fiscal: false
12
+
13
+ cash:
14
+ name: Cash
15
+ cash: true
16
+ fiscal: false
17
+
18
+ fiscal:
19
+ name: Fiscal
20
+ cash: true
21
+ fiscal: true
22
+
23
+ card:
24
+ name: Card
25
+ cash: false
26
+ fiscal: true
27
+
@@ -8,8 +8,12 @@ one:
8
8
  account: one
9
9
  value_cents: 100
10
10
  value_currency: USD
11
+ payment_type: one
12
+ type: Billing::PaymentWithType
11
13
 
12
14
  two:
13
15
  account: one
14
16
  value_cents: 200
15
- value_currency: USD
17
+ value_currency: USD
18
+ payment_type: one
19
+ type: Billing::PaymentWithType
@@ -9,19 +9,19 @@ module Billing
9
9
 
10
10
  test "charge" do
11
11
  charge = @account.charge 3
12
- assert charge.persisted?
12
+ assert charge.try(:persisted?)
13
13
  assert_equal '13 USD'.to_money, @account.total # (1 + 3) + 100% + $1
14
14
  end
15
15
 
16
16
  test "discount" do
17
- discount = @account.modify(-1.00)
18
- assert discount.persisted?
17
+ discount = @account.modify(-1.00, charge: billing_charges(:two))
18
+ assert discount.try(:persisted?)
19
19
  assert_equal '6 USD'.to_money, @account.total
20
20
  end
21
21
 
22
22
  test "surcharge" do
23
- surcharge = @account.modify(1.00)
24
- assert surcharge.persisted?
23
+ surcharge = @account.modify(1.00, charge: billing_charges(:two))
24
+ assert surcharge.try(:persisted?)
25
25
  assert_equal '8 USD'.to_money, @account.total
26
26
  end
27
27
 
@@ -34,10 +34,23 @@ module Billing
34
34
  test "validate positive total" do
35
35
  assert @account.save
36
36
  @account.modify(-500)
37
- assert @account.errors[:total]
37
+ assert @account.errors.messages[:total]
38
38
  assert_raise ActiveRecord::RecordInvalid do
39
39
  @account.save!
40
40
  end
41
41
  end
42
+
43
+ test "account with payments should have origin" do
44
+ assert @account.origin
45
+ assert @account.payments.any?
46
+ @account.origin = nil
47
+ assert_equal false, @account.save
48
+ assert @account.errors.messages[:origin]
49
+ end
50
+
51
+ test "autofin" do
52
+ assert @account.pay billing_payment_types(:one)
53
+ assert @account.finalized_at
54
+ end
42
55
  end
43
56
  end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module Billing
4
+ class DepartmentTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -15,5 +15,18 @@ module Billing
15
15
  # assert_equal Billing::Modifier.args_to_attributes(1, percent_ration: 0.01 ), { fixed_value: '1 USD'.to_money, percent: 0.01 }
16
16
  # assert_equal Billing::Modifier.args_to_attributes(percent_ration: 0.01), { percent_ratio: 0.01 }
17
17
  # end
18
+
19
+ test "allow only one modifier per charge" do
20
+ mod = billing_modifiers(:two).dup
21
+ assert_equal false, mod.save
22
+ assert mod.errors[:charge]
23
+ end
24
+
25
+ test "allow only one global account modifier" do
26
+ mod = billing_modifiers(:two).dup
27
+ assert_equal false, mod.save
28
+ assert mod.errors[:account]
29
+ end
30
+
18
31
  end
19
32
  end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module Billing
4
+ class OperatorTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -4,6 +4,7 @@ module Billing
4
4
  class PaymentTest < ActiveSupport::TestCase
5
5
  setup do
6
6
  @payment = billing_payments(:one)
7
+ @account = @payment.account
7
8
  end
8
9
 
9
10
  # test "args_to_attributes class method" do
@@ -13,5 +14,29 @@ module Billing
13
14
  # assert_equal Billing::Payment.args_to_attributes(billing_payment_type(:one)), { payment_type_id: payment_type.id }
14
15
  # assert_equal Billing::Payment.args_to_attributes(payment_type_id: 2, value: 0.23), { payment_type_id: 2, value: 0.23 }
15
16
  # end
17
+
18
+ test "create" do
19
+ assert_equal 'Billing::PaymentWithType', @account.origin_payment_model
20
+ assert @account.payments.create(type: 'Billing::PaymentWithType', value: 1, payment_type_id: @payment.payment_type_id).persisted?, "Can't create payment"
21
+ end
22
+
23
+ test "should be instance of account's origin_payment_model" do
24
+ payment = @account.payments.new(type: 'Billing::Payment', value: 1, payment_type_id: @payment.payment_type_id)
25
+ assert !payment.save
26
+ assert payment.errors.messages[:account]
27
+ end
28
+
29
+ test "should have same fiscal flag as other account payments" do
30
+ payment = @account.payments.new(type: 'Billing::PaymentWithType', value: 1, payment_type_id: billing_payment_types(:fiscal).id)
31
+ assert !payment.save
32
+ assert payment.errors.messages[:account]
33
+ end
34
+
35
+ test "should be single cash payments" do
36
+ @account.payments.create!(type: 'Billing::PaymentWithType', value: 1, payment_type_id: billing_payment_types(:cash).id)
37
+ payment = @account.payments.new(type: 'Billing::PaymentWithType', value: 1, payment_type_id: billing_payment_types(:cash).id)
38
+ assert !payment.save
39
+ assert payment.errors.messages[:account]
40
+ end
16
41
  end
17
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: billing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4a
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Vangelov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-20 00:00:00.000000000 Z
11
+ date: 2014-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: paper_trail
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: sqlite3
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +80,6 @@ files:
66
80
  - app/assets/javascripts/billing/application.js
67
81
  - app/assets/javascripts/billing/charges.js
68
82
  - app/assets/javascripts/billing/modifiers.js
69
- - app/assets/javascripts/billing/payments.js
70
83
  - app/assets/stylesheets/billing/accounts.css
71
84
  - app/assets/stylesheets/billing/application.css
72
85
  - app/assets/stylesheets/billing/charges.css
@@ -83,17 +96,24 @@ files:
83
96
  - app/helpers/billing/modifiers_helper.rb
84
97
  - app/helpers/billing/payments_helper.rb
85
98
  - app/models/billing/account.rb
86
- - app/models/billing/account_item.rb
87
99
  - app/models/billing/charge.rb
100
+ - app/models/billing/department.rb
88
101
  - app/models/billing/modifier.rb
89
102
  - app/models/billing/modifier_items.rb
103
+ - app/models/billing/operator.rb
90
104
  - app/models/billing/origin.rb
91
105
  - app/models/billing/payment.rb
106
+ - app/models/billing/payment_external.rb
92
107
  - app/models/billing/payment_type.rb
108
+ - app/models/billing/payment_type_fiscal_driver_mapping.rb
93
109
  - app/models/billing/payment_with_type.rb
110
+ - app/models/billing/paypal_express.rb
94
111
  - app/models/billing/plu.rb
95
112
  - app/models/billing/profile.rb
113
+ - app/models/billing/report.rb
96
114
  - app/models/billing/tax_group.rb
115
+ - app/models/billing/version.rb
116
+ - app/models/concerns/billing/account_item.rb
97
117
  - app/views/billing/accounts/index.html.erb
98
118
  - app/views/billing/accounts/new.html.erb
99
119
  - app/views/billing/accounts/show.html.erb
@@ -102,6 +122,7 @@ files:
102
122
  - app/views/billing/modifiers/new.html.erb
103
123
  - app/views/billing/payments/new.html.erb
104
124
  - app/views/layouts/billing/application.html.erb
125
+ - config/initializers/paper_trail.rb
105
126
  - config/routes.rb
106
127
  - db/migrate/20140717180443_create_billing_accounts.rb
107
128
  - db/migrate/20140717181134_create_billing_charges.rb
@@ -118,6 +139,35 @@ files:
118
139
  - db/migrate/20140719110412_add_surcharges_sum_to_billing_account.rb
119
140
  - db/migrate/20140720110811_add_type_to_billing_payment.rb
120
141
  - db/migrate/20140720132559_add_type_to_billing_payment_type.rb
142
+ - db/migrate/20140721172932_create_billing_operators.rb
143
+ - db/migrate/20140721173106_create_billing_departments.rb
144
+ - db/migrate/20140722160242_change_table_base_billing_tax_group.rb
145
+ - db/migrate/20140722160258_change_table_base_billing_operator.rb
146
+ - db/migrate/20140722160529_change_table_base_billing_payment_type.rb
147
+ - db/migrate/20140722160902_change_table_base_billing_departments.rb
148
+ - db/migrate/20140722161743_change_table_base_billing_plus.rb
149
+ - db/migrate/20140722162315_change_table_base_billing_origins.rb
150
+ - db/migrate/20140724173527_add_origin_to_billing_account.rb
151
+ - db/migrate/20140724173917_remove_origin_and_fiscal_defice_from_billing_payment.rb
152
+ - db/migrate/20140725122914_add_status_to_billing_payment.rb
153
+ - db/migrate/20140725142525_eqalize_schemas_billing_charge.rb
154
+ - db/migrate/20140725143734_eqalize_schemas_billing_department.rb
155
+ - db/migrate/20140725145640_eqalize_schemas_billing_closure.rb
156
+ - db/migrate/20140725145953_eqalize_schemas_billing_operators.rb
157
+ - db/migrate/20140725150329_eqalize_schemas_billing_origin.rb
158
+ - db/migrate/20140725151522_eqalize_schemas_billing_payment_type.rb
159
+ - db/migrate/20140725152125_eqalize_schemas_billing_payment.rb
160
+ - db/migrate/20140725153215_eqalize_schemas_billing_version.rb
161
+ - db/migrate/20140725153658_eqalize_schemas_billing_pt_fp_mapping.rb
162
+ - db/migrate/20140725164847_add_extface_job_to_billing_account.rb
163
+ - db/migrate/20140726163220_rename_closure_to_billing_report.rb
164
+ - db/migrate/20140726165718_remove_closure_from_billing_account.rb
165
+ - db/migrate/20140726170002_add_report_to_billing_account.rb
166
+ - db/migrate/20140728110230_add_autofin_and_finalized_at_to_billing_account.rb
167
+ - db/migrate/20140729083050_add_name_to_billing_account.rb
168
+ - db/migrate/20140729083408_add_number_to_billing_account.rb
169
+ - db/migrate/20140729180849_add_deleted_at_to_billing_modifier.rb
170
+ - db/migrate/20140729182146_add_deleted_at_to_billing_account.rb
121
171
  - lib/billing.rb
122
172
  - lib/billing/billable.rb
123
173
  - lib/billing/engine.rb
@@ -201,7 +251,9 @@ files:
201
251
  - test/dummy/tmp/cache/assets/test/sprockets/fbf1489a0c3d66a329f070c10cd77a03
202
252
  - test/fixtures/billing/accounts.yml
203
253
  - test/fixtures/billing/charges.yml
254
+ - test/fixtures/billing/departments.yml
204
255
  - test/fixtures/billing/modifiers.yml
256
+ - test/fixtures/billing/operators.yml
205
257
  - test/fixtures/billing/origins.yml
206
258
  - test/fixtures/billing/payment_types.yml
207
259
  - test/fixtures/billing/payments.yml
@@ -216,7 +268,9 @@ files:
216
268
  - test/integration/navigation_test.rb
217
269
  - test/models/billing/account_test.rb
218
270
  - test/models/billing/charge_test.rb
271
+ - test/models/billing/department_test.rb
219
272
  - test/models/billing/modifier_test.rb
273
+ - test/models/billing/operator_test.rb
220
274
  - test/models/billing/origin_test.rb
221
275
  - test/models/billing/payment_test.rb
222
276
  - test/models/billing/payment_type_test.rb
@@ -239,9 +293,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
239
293
  version: '0'
240
294
  required_rubygems_version: !ruby/object:Gem::Requirement
241
295
  requirements:
242
- - - ">="
296
+ - - ">"
243
297
  - !ruby/object:Gem::Version
244
- version: '0'
298
+ version: 1.3.1
245
299
  requirements: []
246
300
  rubyforge_project:
247
301
  rubygems_version: 2.2.2
@@ -255,8 +309,10 @@ test_files:
255
309
  - test/fixtures/billing/plus.yml
256
310
  - test/fixtures/billing/payments.yml
257
311
  - test/fixtures/billing/charges.yml
312
+ - test/fixtures/billing/departments.yml
258
313
  - test/fixtures/billing/modifiers.yml
259
314
  - test/fixtures/billing/profiles.yml
315
+ - test/fixtures/billing/operators.yml
260
316
  - test/fixtures/billing/accounts.yml
261
317
  - test/fixtures/billing/tax_groups.yml
262
318
  - test/fixtures/profiles.yml
@@ -341,7 +397,9 @@ test_files:
341
397
  - test/models/billing/tax_group_test.rb
342
398
  - test/models/billing/account_test.rb
343
399
  - test/models/billing/plu_test.rb
400
+ - test/models/billing/department_test.rb
344
401
  - test/models/billing/payment_test.rb
402
+ - test/models/billing/operator_test.rb
345
403
  - test/models/billing/origin_test.rb
346
404
  - test/models/billing/profile_test.rb
347
405
  - test/models/billing/payment_type_test.rb
@@ -1,2 +0,0 @@
1
- // Place all the behaviors and hooks related to the matching controller here.
2
- // All this logic will automatically be available in application.js.