uomi 0.2.13 → 0.2.14
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/.rvmrc +1 -1
- data/Gemfile +1 -1
- data/README.md +4 -4
- data/lib/generators/active_record/templates/migration.rb +12 -12
- data/lib/generators/active_record/{invoicing_generator.rb → uomi_generator.rb} +3 -3
- data/lib/{invoicing → uomi}/buyer.rb +1 -1
- data/lib/{invoicing → uomi}/credit_note.rb +1 -1
- data/lib/{invoicing → uomi}/credit_note_credit_transaction.rb +1 -1
- data/lib/{invoicing → uomi}/credit_note_invoice.rb +1 -1
- data/lib/{invoicing → uomi}/credit_transaction.rb +1 -1
- data/lib/{invoicing → uomi}/debit_transaction.rb +1 -1
- data/lib/{invoicing → uomi}/exception.rb +1 -1
- data/lib/{invoicing → uomi}/invoice.rb +1 -1
- data/lib/{invoicing → uomi}/invoice_adjustment.rb +1 -1
- data/lib/{invoicing → uomi}/invoice_decorator.rb +1 -1
- data/lib/{invoicing → uomi}/invoiceable.rb +1 -1
- data/lib/{invoicing → uomi}/late_payment.rb +1 -1
- data/lib/{invoicing → uomi}/line_item.rb +1 -1
- data/lib/{invoicing → uomi}/line_item_type.rb +1 -1
- data/lib/{invoicing → uomi}/overdue_invoice.rb +1 -1
- data/lib/{invoicing → uomi}/payment_reference.rb +1 -1
- data/lib/{invoicing → uomi}/seller.rb +1 -1
- data/lib/{invoicing → uomi}/transaction.rb +1 -1
- data/lib/uomi/version.rb +3 -0
- data/lib/uomi.rb +46 -0
- data/spec/internal/config/database.yml.sample +1 -1
- data/spec/internal/db/schema.rb +11 -11
- data/spec/lib/{invoicing → uomi}/credit_note_spec.rb +9 -9
- data/spec/lib/{invoicing → uomi}/invoice_adjustment_spec.rb +7 -7
- data/spec/lib/{invoicing → uomi}/invoice_late_payment_spec.rb +1 -1
- data/spec/lib/{invoicing → uomi}/invoice_spec.rb +63 -63
- data/spec/lib/uomi/line_item_spec.rb +14 -0
- data/spec/lib/{invoicing → uomi}/overdue_invoice_spec.rb +18 -18
- data/spec/support/helpers.rb +6 -6
- data/{invoicing.gemspec → uomi.gemspec} +4 -4
- metadata +37 -37
- data/lib/invoicing/version.rb +0 -3
- data/lib/invoicing.rb +0 -46
- data/spec/lib/invoicing/line_item_spec.rb +0 -14
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm use 1.9.2@
|
1
|
+
rvm use 1.9.2@uomi --create
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
[](http://travis-ci.org/tehtorq/uomi)
|
3
3
|
|
4
4
|
Basic Usage
|
5
5
|
|
@@ -7,7 +7,7 @@ Basic Usage
|
|
7
7
|
book = Book.find(1) # implements CostItem
|
8
8
|
decorations = {whatever_you_want: 'here'}
|
9
9
|
|
10
|
-
invoice =
|
10
|
+
invoice = Uomi::generate_invoice do
|
11
11
|
from seller
|
12
12
|
line_item book
|
13
13
|
due Time.now + 7.days
|
@@ -21,13 +21,13 @@ A default invoice number will be set with the format INV[invoice id].
|
|
21
21
|
|
22
22
|
A custom invoice number can be specified as follows:
|
23
23
|
|
24
|
-
invoice =
|
24
|
+
invoice = Uomi::generate_invoice do
|
25
25
|
numbered "CUSTOMREF123"
|
26
26
|
end
|
27
27
|
|
28
28
|
You can specify a custom invoice number containing the invoice id as follows:
|
29
29
|
|
30
|
-
invoice =
|
30
|
+
invoice = Uomi::generate_invoice do
|
31
31
|
numbered "CUSTOMREF{id}"
|
32
32
|
end
|
33
33
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
class
|
1
|
+
class CreateUomiTables < ActiveRecord::Migration
|
2
2
|
def self.change
|
3
3
|
|
4
|
-
create_table "
|
4
|
+
create_table "uomi_late_payments", :force => true do |t|
|
5
5
|
t.integer "invoice_id"
|
6
6
|
t.integer "amount"
|
7
7
|
t.datetime "penalty_date"
|
@@ -9,7 +9,7 @@ class CreateInvoicingTables < ActiveRecord::Migration
|
|
9
9
|
t.timestamps
|
10
10
|
end
|
11
11
|
|
12
|
-
create_table "
|
12
|
+
create_table "uomi_line_items", :force => true do |t|
|
13
13
|
t.integer "invoice_id"
|
14
14
|
t.string "description"
|
15
15
|
t.integer "amount"
|
@@ -20,14 +20,14 @@ class CreateInvoicingTables < ActiveRecord::Migration
|
|
20
20
|
t.timestamps
|
21
21
|
end
|
22
22
|
|
23
|
-
create_table "
|
23
|
+
create_table "uomi_transactions", :force => true do |t|
|
24
24
|
t.integer "invoice_id"
|
25
25
|
t.string "type"
|
26
26
|
t.integer "amount"
|
27
27
|
t.timestamps
|
28
28
|
end
|
29
29
|
|
30
|
-
create_table "
|
30
|
+
create_table "uomi_invoices", :force => true do |t|
|
31
31
|
t.integer "seller_id"
|
32
32
|
t.integer "buyer_id"
|
33
33
|
t.string "invoice_number"
|
@@ -41,41 +41,41 @@ class CreateInvoicingTables < ActiveRecord::Migration
|
|
41
41
|
t.timestamps
|
42
42
|
end
|
43
43
|
|
44
|
-
create_table "
|
44
|
+
create_table "uomi_payment_references", :force => true do |t|
|
45
45
|
t.integer "invoice_id"
|
46
46
|
t.string "reference"
|
47
47
|
t.timestamps
|
48
48
|
end
|
49
49
|
|
50
|
-
create_table "
|
50
|
+
create_table "uomi_sellers", :force => true do |t|
|
51
51
|
t.integer "sellerable_id"
|
52
52
|
t.string "sellerable_type"
|
53
53
|
t.timestamps
|
54
54
|
end
|
55
55
|
|
56
|
-
create_table "
|
56
|
+
create_table "uomi_buyers", :force => true do |t|
|
57
57
|
t.integer "buyerable_id"
|
58
58
|
t.string "buyerable_type"
|
59
59
|
t.timestamps
|
60
60
|
end
|
61
61
|
|
62
|
-
create_table "
|
62
|
+
create_table "uomi_invoice_decorators", :force => true do |t|
|
63
63
|
t.integer "invoice_id"
|
64
64
|
t.text "data"
|
65
65
|
t.timestamps
|
66
66
|
end
|
67
67
|
|
68
|
-
create_table "
|
68
|
+
create_table "uomi_credit_note_invoices", :force => true do |t|
|
69
69
|
t.integer "invoice_id"
|
70
70
|
t.integer "credit_note_id"
|
71
71
|
end
|
72
72
|
|
73
|
-
create_table "
|
73
|
+
create_table "uomi_credit_note_credit_transactions", :force => true do |t|
|
74
74
|
t.integer "credit_note_id"
|
75
75
|
t.integer "transaction_id"
|
76
76
|
end
|
77
77
|
|
78
|
-
create_table "
|
78
|
+
create_table "uomi_line_item_types", :force => true do |t|
|
79
79
|
t.string "name"
|
80
80
|
end
|
81
81
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Uomi
|
2
2
|
module Generators
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
4
4
|
include Rails::Generators::Migration
|
@@ -6,7 +6,7 @@ module Invoicing
|
|
6
6
|
source_root File.expand_path("../templates", __FILE__)
|
7
7
|
|
8
8
|
desc <<-CONTENT
|
9
|
-
Copies the
|
9
|
+
Copies the uomi migration file to the migrations
|
10
10
|
folder.
|
11
11
|
|
12
12
|
Please run rake db:migrate once the installer is
|
@@ -23,7 +23,7 @@ module Invoicing
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def create_migration_file
|
26
|
-
migration_template 'migration.rb', 'db/migrate/
|
26
|
+
migration_template 'migration.rb', 'db/migrate/create_uomi_tables.rb'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/lib/uomi/version.rb
ADDED
data/lib/uomi.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "workflow"
|
3
|
+
require "uomi/version"
|
4
|
+
|
5
|
+
module Uomi
|
6
|
+
|
7
|
+
def self.table_name_prefix
|
8
|
+
'uomi_'
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.generate_invoice(&block)
|
12
|
+
invoice = Invoice.new
|
13
|
+
invoice.instance_eval(&block)
|
14
|
+
invoice.save!
|
15
|
+
invoice
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.generate_credit_note(&block)
|
19
|
+
credit_note = CreditNote.new
|
20
|
+
credit_note.instance_eval(&block)
|
21
|
+
credit_note.save!
|
22
|
+
credit_note.issue!
|
23
|
+
credit_note
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
require "uomi/exception"
|
29
|
+
require "uomi/invoiceable"
|
30
|
+
require "uomi/transaction"
|
31
|
+
require "uomi/credit_transaction"
|
32
|
+
require "uomi/debit_transaction"
|
33
|
+
require "uomi/late_payment"
|
34
|
+
require "uomi/line_item"
|
35
|
+
require "uomi/payment_reference"
|
36
|
+
require "uomi/seller"
|
37
|
+
require "uomi/buyer"
|
38
|
+
require "uomi/invoice_decorator"
|
39
|
+
require "uomi/credit_note_invoice"
|
40
|
+
require "uomi/credit_note_credit_transaction"
|
41
|
+
|
42
|
+
require "uomi/invoice"
|
43
|
+
require "uomi/credit_note"
|
44
|
+
require "uomi/overdue_invoice"
|
45
|
+
require "uomi/invoice_adjustment"
|
46
|
+
require "uomi/line_item_type"
|
data/spec/internal/db/schema.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
ActiveRecord::Schema.define do
|
2
2
|
|
3
|
-
create_table "
|
3
|
+
create_table "uomi_late_payments", :force => true do |t|
|
4
4
|
t.integer "invoice_id"
|
5
5
|
t.integer "amount"
|
6
6
|
t.datetime "penalty_date"
|
@@ -8,7 +8,7 @@ ActiveRecord::Schema.define do
|
|
8
8
|
t.timestamps
|
9
9
|
end
|
10
10
|
|
11
|
-
create_table "
|
11
|
+
create_table "uomi_line_items", :force => true do |t|
|
12
12
|
t.integer "invoice_id"
|
13
13
|
t.string "description"
|
14
14
|
t.integer "amount"
|
@@ -19,14 +19,14 @@ ActiveRecord::Schema.define do
|
|
19
19
|
t.timestamps
|
20
20
|
end
|
21
21
|
|
22
|
-
create_table "
|
22
|
+
create_table "uomi_transactions", :force => true do |t|
|
23
23
|
t.integer "invoice_id"
|
24
24
|
t.string "type"
|
25
25
|
t.integer "amount"
|
26
26
|
t.timestamps
|
27
27
|
end
|
28
28
|
|
29
|
-
create_table "
|
29
|
+
create_table "uomi_invoices", :force => true do |t|
|
30
30
|
t.integer "seller_id"
|
31
31
|
t.integer "buyer_id"
|
32
32
|
t.string "invoice_number"
|
@@ -40,41 +40,41 @@ ActiveRecord::Schema.define do
|
|
40
40
|
t.timestamps
|
41
41
|
end
|
42
42
|
|
43
|
-
create_table "
|
43
|
+
create_table "uomi_payment_references", :force => true do |t|
|
44
44
|
t.integer "invoice_id"
|
45
45
|
t.string "reference"
|
46
46
|
t.timestamps
|
47
47
|
end
|
48
48
|
|
49
|
-
create_table "
|
49
|
+
create_table "uomi_sellers", :force => true do |t|
|
50
50
|
t.integer "sellerable_id"
|
51
51
|
t.string "sellerable_type"
|
52
52
|
t.timestamps
|
53
53
|
end
|
54
54
|
|
55
|
-
create_table "
|
55
|
+
create_table "uomi_buyers", :force => true do |t|
|
56
56
|
t.integer "buyerable_id"
|
57
57
|
t.string "buyerable_type"
|
58
58
|
t.timestamps
|
59
59
|
end
|
60
60
|
|
61
|
-
create_table "
|
61
|
+
create_table "uomi_invoice_decorators", :force => true do |t|
|
62
62
|
t.integer "invoice_id"
|
63
63
|
t.text "data"
|
64
64
|
t.timestamps
|
65
65
|
end
|
66
66
|
|
67
|
-
create_table "
|
67
|
+
create_table "uomi_credit_note_invoices", :force => true do |t|
|
68
68
|
t.integer "invoice_id"
|
69
69
|
t.integer "credit_note_id"
|
70
70
|
end
|
71
71
|
|
72
|
-
create_table "
|
72
|
+
create_table "uomi_credit_note_credit_transactions", :force => true do |t|
|
73
73
|
t.integer "credit_note_id"
|
74
74
|
t.integer "transaction_id"
|
75
75
|
end
|
76
76
|
|
77
|
-
create_table "
|
77
|
+
create_table "uomi_line_item_types", :force => true do |t|
|
78
78
|
t.string "name"
|
79
79
|
end
|
80
80
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Uomi::CreditNote do
|
4
4
|
include Helpers
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
tear_it_down
|
8
8
|
|
9
|
-
invoice_buyer =
|
10
|
-
invoice_seller =
|
9
|
+
invoice_buyer = Uomi::DebitTransaction.create!
|
10
|
+
invoice_seller = Uomi::DebitTransaction.create!
|
11
11
|
|
12
|
-
@invoice =
|
12
|
+
@invoice = Uomi::generate_invoice do
|
13
13
|
to invoice_buyer
|
14
14
|
from invoice_seller
|
15
15
|
|
@@ -32,7 +32,7 @@ describe Invoicing::CreditNote do
|
|
32
32
|
before(:each) do
|
33
33
|
@invoice.line_items.each do |li|
|
34
34
|
li.invoiceable = li
|
35
|
-
li.invoiceable.extend(
|
35
|
+
li.invoiceable.extend(Uomi::Invoiceable)
|
36
36
|
li.amount = 0
|
37
37
|
li.tax = 0
|
38
38
|
li.save!
|
@@ -43,7 +43,7 @@ describe Invoicing::CreditNote do
|
|
43
43
|
|
44
44
|
it "should raise an exception if the invoice is not in an issued state" do
|
45
45
|
lambda {
|
46
|
-
@credit_note =
|
46
|
+
@credit_note = Uomi::generate_credit_note do
|
47
47
|
against_invoice @invoice
|
48
48
|
end
|
49
49
|
}.should raise_error(RuntimeError, "You must allocate a credit note against an invoice")
|
@@ -55,7 +55,7 @@ describe Invoicing::CreditNote do
|
|
55
55
|
invoice = @invoice
|
56
56
|
line_items = invoice.line_items
|
57
57
|
|
58
|
-
@credit_note =
|
58
|
+
@credit_note = Uomi::generate_credit_note do
|
59
59
|
line_items.each do |line_item|
|
60
60
|
credit amount: line_item.amount, line_item: line_item, description: "Credit note for Line Item #{line_item.id}", tax: 0
|
61
61
|
end
|
@@ -111,7 +111,7 @@ describe Invoicing::CreditNote do
|
|
111
111
|
context "When applying credits to the invoiceables" do
|
112
112
|
|
113
113
|
it "should receive handle credit for each line item being credited" do
|
114
|
-
credit_note =
|
114
|
+
credit_note = Uomi::CreditNote.new
|
115
115
|
credit_note.line_items = @invoice.line_items
|
116
116
|
|
117
117
|
credit_note.line_items.map(&:invoiceable).compact.each do |item|
|
@@ -126,7 +126,7 @@ describe Invoicing::CreditNote do
|
|
126
126
|
context "trying to create a standalone credit note" do
|
127
127
|
|
128
128
|
it "should raise an error if no invoice is specified" do
|
129
|
-
expect {
|
129
|
+
expect {Uomi::generate_credit_note do
|
130
130
|
line_items.each do |line_item|
|
131
131
|
credit amount: 500, description: "Credit note for Line Item #{line_item.id}", tax: 0
|
132
132
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Uomi::InvoiceAdjustment do
|
4
4
|
include Helpers
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
tear_it_down
|
8
8
|
|
9
|
-
buyer =
|
9
|
+
buyer = Uomi::DebitTransaction.create!
|
10
10
|
|
11
|
-
@invoice =
|
11
|
+
@invoice = Uomi::generate_invoice do
|
12
12
|
to buyer
|
13
13
|
numbered "INV123"
|
14
14
|
|
@@ -30,7 +30,7 @@ describe Invoicing::InvoiceAdjustment do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should allow the buyer to be changed" do
|
33
|
-
new_buyer =
|
33
|
+
new_buyer = Uomi::DebitTransaction.create!
|
34
34
|
|
35
35
|
@invoice.adjust do
|
36
36
|
to new_buyer
|
@@ -68,7 +68,7 @@ describe Invoicing::InvoiceAdjustment do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should allow line items to be added" do
|
71
|
-
item_to_invoice = @invoice.extend(
|
71
|
+
item_to_invoice = @invoice.extend(Uomi::Invoiceable)
|
72
72
|
@invoice.line_items.count.should == 3
|
73
73
|
|
74
74
|
@invoice.adjust do
|
@@ -81,7 +81,7 @@ describe Invoicing::InvoiceAdjustment do
|
|
81
81
|
|
82
82
|
it "should allow line items to be edited" do
|
83
83
|
line_item = @invoice.line_items.first
|
84
|
-
item_to_invoice = @invoice.extend(
|
84
|
+
item_to_invoice = @invoice.extend(Uomi::Invoiceable)
|
85
85
|
|
86
86
|
@invoice.adjust do
|
87
87
|
edit_line_item(line_item, {description: "Modified Line Item", amount: 500})
|
@@ -128,7 +128,7 @@ describe Invoicing::InvoiceAdjustment do
|
|
128
128
|
@invoice.adjust do
|
129
129
|
due Date.tomorrow
|
130
130
|
end
|
131
|
-
}.to raise_error(
|
131
|
+
}.to raise_error(Uomi::CannotAdjustIssuedDocument)
|
132
132
|
end
|
133
133
|
|
134
134
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Uomi::Invoice do
|
4
4
|
include Helpers
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
tear_it_down
|
8
8
|
|
9
|
-
@invoice =
|
9
|
+
@invoice = Uomi::generate_invoice do
|
10
10
|
line_item description: "Line Item 1", amount: 1101, line_item_type_id: 1
|
11
11
|
line_item description: "Line Item 2", amount: 5097, line_item_type_id: 1
|
12
12
|
line_item description: "Line Item 3", amount: 1714, line_item_type_id: 1
|
@@ -18,7 +18,7 @@ describe Invoicing::Invoice do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should be able to add a line item" do
|
21
|
-
invoice =
|
21
|
+
invoice = Uomi::generate_invoice do
|
22
22
|
line_item description: "Line Item 1", amount: 1101, line_item_type_id: 1
|
23
23
|
end
|
24
24
|
|
@@ -81,78 +81,78 @@ describe Invoicing::Invoice do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should find draft invoices" do
|
84
|
-
issued_invoice =
|
84
|
+
issued_invoice = Uomi::generate_invoice do
|
85
85
|
line_item description: "Line Item 1", amount: 1101, line_item_type_id: 1
|
86
86
|
end
|
87
87
|
|
88
88
|
issued_invoice.issue!
|
89
89
|
|
90
|
-
draft_invoice =
|
90
|
+
draft_invoice = Uomi::generate_invoice do
|
91
91
|
line_item description: "Line Item 1", amount: 1101, line_item_type_id: 1, line_item_type_id: 1
|
92
92
|
end
|
93
93
|
|
94
|
-
|
95
|
-
|
94
|
+
Uomi::Invoice.draft.count.should == 1
|
95
|
+
Uomi::Invoice.draft.first.should == draft_invoice
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should find issued invoices" do
|
99
|
-
issued_invoice =
|
99
|
+
issued_invoice = Uomi::generate_invoice do
|
100
100
|
line_item description: "Line Item 1", amount: 1101, line_item_type_id: 1
|
101
101
|
end
|
102
102
|
|
103
103
|
issued_invoice.issue!
|
104
104
|
|
105
|
-
other_invoice =
|
105
|
+
other_invoice = Uomi::generate_invoice do
|
106
106
|
line_item description: "Line Item 1", amount: 1101, line_item_type_id: 1
|
107
107
|
end
|
108
108
|
|
109
|
-
|
110
|
-
|
109
|
+
Uomi::Invoice.issued.count.should == 1
|
110
|
+
Uomi::Invoice.issued.first.should == issued_invoice
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should find owing invoices" do
|
114
|
-
owing_invoice =
|
114
|
+
owing_invoice = Uomi::generate_invoice do
|
115
115
|
line_item description: "Line Item 1", amount: 1101, line_item_type_id: 1
|
116
116
|
end
|
117
117
|
|
118
118
|
owing_invoice.issue!
|
119
119
|
|
120
|
-
other_invoice =
|
120
|
+
other_invoice = Uomi::generate_invoice do
|
121
121
|
line_item description: "Line Item 1", amount: 1101, line_item_type_id: 1
|
122
122
|
end
|
123
123
|
|
124
|
-
|
125
|
-
|
124
|
+
Uomi::Invoice.owing.count.should == 1
|
125
|
+
Uomi::Invoice.owing.first.should == owing_invoice
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should find settled invoices" do
|
129
|
-
settled_invoice =
|
129
|
+
settled_invoice = Uomi::generate_invoice do
|
130
130
|
end
|
131
131
|
|
132
132
|
settled_invoice.issue!
|
133
133
|
|
134
|
-
other_invoice =
|
134
|
+
other_invoice = Uomi::generate_invoice do
|
135
135
|
line_item description: "Line Item 1", amount: 1101, line_item_type_id: 1
|
136
136
|
end
|
137
137
|
|
138
|
-
|
139
|
-
|
138
|
+
Uomi::Invoice.settled.count.should == 1
|
139
|
+
Uomi::Invoice.settled.first.should == settled_invoice
|
140
140
|
end
|
141
141
|
|
142
142
|
it "should find voided invoices" do
|
143
|
-
voided_invoice =
|
143
|
+
voided_invoice = Uomi::generate_invoice do
|
144
144
|
line_item description: "Line Item 1", amount: 1101, line_item_type_id: 1
|
145
145
|
end
|
146
146
|
|
147
147
|
voided_invoice.issue!
|
148
148
|
voided_invoice.void!
|
149
149
|
|
150
|
-
other_invoice =
|
150
|
+
other_invoice = Uomi::generate_invoice do
|
151
151
|
line_item description: "Line Item 1", amount: 1101, line_item_type_id: 1
|
152
152
|
end
|
153
153
|
|
154
|
-
|
155
|
-
|
154
|
+
Uomi::Invoice.voided.count.should == 1
|
155
|
+
Uomi::Invoice.voided.first.should == voided_invoice
|
156
156
|
end
|
157
157
|
|
158
158
|
end
|
@@ -164,7 +164,7 @@ describe Invoicing::Invoice do
|
|
164
164
|
end
|
165
165
|
|
166
166
|
it "should allow a specific invoice number to be specified" do
|
167
|
-
invoice =
|
167
|
+
invoice = Uomi::generate_invoice do
|
168
168
|
numbered "CUSTOMREF123"
|
169
169
|
end
|
170
170
|
|
@@ -172,7 +172,7 @@ describe Invoicing::Invoice do
|
|
172
172
|
end
|
173
173
|
|
174
174
|
it "should allow a custom invoice number format to be specified containing the invoice id" do
|
175
|
-
invoice =
|
175
|
+
invoice = Uomi::generate_invoice do
|
176
176
|
numbered "CUSTOMREF{id}"
|
177
177
|
end
|
178
178
|
|
@@ -180,15 +180,15 @@ describe Invoicing::Invoice do
|
|
180
180
|
end
|
181
181
|
|
182
182
|
it "should validate that the invoice number is unique per seller" do
|
183
|
-
seller =
|
183
|
+
seller = Uomi::DebitTransaction.create!
|
184
184
|
|
185
|
-
invoice =
|
185
|
+
invoice = Uomi::generate_invoice do
|
186
186
|
numbered "CUSTOMREF123"
|
187
187
|
from seller
|
188
188
|
end
|
189
189
|
|
190
190
|
expect {
|
191
|
-
invoice =
|
191
|
+
invoice = Uomi::generate_invoice do
|
192
192
|
numbered "CUSTOMREF123"
|
193
193
|
from seller
|
194
194
|
end
|
@@ -196,17 +196,17 @@ describe Invoicing::Invoice do
|
|
196
196
|
end
|
197
197
|
|
198
198
|
it "should allow two invoices with the same invoice number, but from different sellers" do
|
199
|
-
first_seller =
|
199
|
+
first_seller = Uomi::DebitTransaction.create!
|
200
200
|
|
201
|
-
invoice =
|
201
|
+
invoice = Uomi::generate_invoice do
|
202
202
|
numbered "CUSTOMREF123"
|
203
203
|
from first_seller
|
204
204
|
end
|
205
205
|
|
206
|
-
second_seller =
|
206
|
+
second_seller = Uomi::DebitTransaction.create!
|
207
207
|
|
208
208
|
expect {
|
209
|
-
invoice =
|
209
|
+
invoice = Uomi::generate_invoice do
|
210
210
|
numbered "CUSTOMREF123"
|
211
211
|
from second_seller
|
212
212
|
end
|
@@ -216,7 +216,7 @@ describe Invoicing::Invoice do
|
|
216
216
|
end
|
217
217
|
|
218
218
|
it "should be able to register multiple payment references to look up invoices by" do
|
219
|
-
invoice =
|
219
|
+
invoice = Uomi::generate_invoice do
|
220
220
|
payment_reference "Mr. Anderson"
|
221
221
|
payment_reference "REF23934"
|
222
222
|
end
|
@@ -225,9 +225,9 @@ describe Invoicing::Invoice do
|
|
225
225
|
end
|
226
226
|
|
227
227
|
it "should be able to specify the seller" do
|
228
|
-
seller =
|
228
|
+
seller = Uomi::DebitTransaction.create!
|
229
229
|
|
230
|
-
invoice =
|
230
|
+
invoice = Uomi::generate_invoice do
|
231
231
|
from seller
|
232
232
|
end
|
233
233
|
|
@@ -235,26 +235,26 @@ describe Invoicing::Invoice do
|
|
235
235
|
end
|
236
236
|
|
237
237
|
it "should be able to find invoices for a given reference" do
|
238
|
-
invoice1 =
|
238
|
+
invoice1 = Uomi::generate_invoice do
|
239
239
|
payment_reference "Mr. Anderson"
|
240
240
|
payment_reference "REF23934"
|
241
241
|
end
|
242
242
|
|
243
|
-
invoice2 =
|
243
|
+
invoice2 = Uomi::generate_invoice do
|
244
244
|
payment_reference "Mr. Anderson"
|
245
245
|
end
|
246
246
|
|
247
|
-
|
248
|
-
|
249
|
-
|
247
|
+
Uomi::Invoice.for_payment_reference("Mr. Anderson").should == [invoice1, invoice2]
|
248
|
+
Uomi::Invoice.for_payment_reference("REF23934").should == [invoice1]
|
249
|
+
Uomi::Invoice.for_payment_reference("My Payment").should == []
|
250
250
|
end
|
251
251
|
|
252
252
|
context "when adding a line item" do
|
253
253
|
|
254
254
|
it "should be able to attach an invoiceable item to the line item" do
|
255
|
-
item_to_invoice = @invoice.extend(
|
255
|
+
item_to_invoice = @invoice.extend(Uomi::Invoiceable)
|
256
256
|
|
257
|
-
invoice =
|
257
|
+
invoice = Uomi::generate_invoice do
|
258
258
|
line_item item_to_invoice
|
259
259
|
end
|
260
260
|
|
@@ -263,11 +263,11 @@ describe Invoicing::Invoice do
|
|
263
263
|
end
|
264
264
|
|
265
265
|
it "should be able to add decoration data to the invoice" do
|
266
|
-
item_to_invoice = @invoice.extend(
|
266
|
+
item_to_invoice = @invoice.extend(Uomi::Invoiceable)
|
267
267
|
|
268
268
|
decoration = {invoicee: "Bob Jones"}
|
269
269
|
|
270
|
-
invoice =
|
270
|
+
invoice = Uomi::generate_invoice do
|
271
271
|
line_item item_to_invoice
|
272
272
|
decorate_with decoration
|
273
273
|
end
|
@@ -278,40 +278,40 @@ describe Invoicing::Invoice do
|
|
278
278
|
context "destroying an invoice" do
|
279
279
|
|
280
280
|
it "should destroy its associated line items" do
|
281
|
-
|
282
|
-
|
281
|
+
Uomi::LineItem.create! amount: 0
|
282
|
+
Uomi::LineItem.count.should == 5
|
283
283
|
@invoice.destroy
|
284
|
-
|
284
|
+
Uomi::LineItem.count.should == 1
|
285
285
|
end
|
286
286
|
|
287
287
|
it "should destroy its associated transactions" do
|
288
288
|
@invoice.issue!
|
289
|
-
|
290
|
-
|
289
|
+
Uomi::Transaction.create!
|
290
|
+
Uomi::Transaction.count.should == 2
|
291
291
|
@invoice.destroy
|
292
|
-
|
292
|
+
Uomi::Transaction.count.should == 1
|
293
293
|
end
|
294
294
|
|
295
295
|
it "should destroy its associated payment_references" do
|
296
|
-
|
297
|
-
|
296
|
+
Uomi::PaymentReference.create!
|
297
|
+
Uomi::PaymentReference.count.should == 2
|
298
298
|
@invoice.destroy
|
299
|
-
|
299
|
+
Uomi::PaymentReference.count.should == 1
|
300
300
|
end
|
301
301
|
|
302
302
|
it "should destroy its associated late payments" do
|
303
|
-
|
304
|
-
|
305
|
-
|
303
|
+
Uomi::LatePayment.create!
|
304
|
+
Uomi::LatePayment.create! invoice_id: @invoice.id
|
305
|
+
Uomi::LatePayment.count.should == 2
|
306
306
|
@invoice.destroy
|
307
|
-
|
307
|
+
Uomi::LatePayment.count.should == 1
|
308
308
|
end
|
309
309
|
|
310
310
|
it "should destroy its associated decorator" do
|
311
|
-
|
312
|
-
|
311
|
+
Uomi::InvoiceDecorator.create!
|
312
|
+
Uomi::InvoiceDecorator.count.should == 2
|
313
313
|
@invoice.destroy
|
314
|
-
|
314
|
+
Uomi::InvoiceDecorator.count.should == 1
|
315
315
|
end
|
316
316
|
|
317
317
|
end
|
@@ -378,7 +378,7 @@ describe Invoicing::Invoice do
|
|
378
378
|
end
|
379
379
|
|
380
380
|
it "should raise an error when voiding the invoice" do
|
381
|
-
lambda { @invoice.void! }.should raise_error(
|
381
|
+
lambda { @invoice.void! }.should raise_error(Uomi::CannotVoidDocumentException, "Cannot void a document that has a transaction recorded against it!")
|
382
382
|
end
|
383
383
|
end
|
384
384
|
end
|
@@ -386,10 +386,10 @@ describe Invoicing::Invoice do
|
|
386
386
|
|
387
387
|
context "Hooks" do
|
388
388
|
before(:each) do
|
389
|
-
item_to_invoice = @invoice.extend(
|
389
|
+
item_to_invoice = @invoice.extend(Uomi::Invoiceable)
|
390
390
|
item_to_invoice.amount = 10
|
391
391
|
|
392
|
-
@invoice2 =
|
392
|
+
@invoice2 = Uomi::generate_invoice do
|
393
393
|
line_item item_to_invoice
|
394
394
|
end
|
395
395
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Uomi::LineItem do
|
4
|
+
include Helpers
|
5
|
+
|
6
|
+
it "should validate that the amount is positive" do
|
7
|
+
expect {Uomi::LineItem.create! amount: -0.01}.to raise_error ActiveRecord::RecordInvalid, "Validation failed: Amount must be greater than or equal to 0"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should validate that the amount is specified" do
|
11
|
+
expect {Uomi::LineItem.create! amount: nil}.to raise_error ActiveRecord::RecordInvalid, "Validation failed: Amount is not a number, Amount can't be blank"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Uomi::OverdueInvoice do
|
4
4
|
include Helpers
|
5
5
|
|
6
6
|
before(:each) do
|
@@ -8,59 +8,59 @@ describe Invoicing::OverdueInvoice do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should find all invoices which are overdue" do
|
11
|
-
|
11
|
+
Uomi::generate_invoice do
|
12
12
|
line_item description: "Line Item 1", amount: 1101
|
13
13
|
due Time.now
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
Uomi::generate_invoice do
|
17
17
|
due Time.now - 1.days
|
18
18
|
line_item description: "Line Item 1", amount: 1101
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
Uomi::generate_invoice do
|
22
22
|
due Time.now - 1.days
|
23
23
|
line_item description: "Line Item 1", amount: 0
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
Uomi::Invoice.all.each(&:issue!)
|
27
|
+
Uomi::OverdueInvoice.all.count.should == 1
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should record a late payment against an invoice which is overdue" do
|
31
|
-
|
31
|
+
Uomi::generate_invoice do
|
32
32
|
due Time.now
|
33
33
|
line_item description: "Line Item 1", amount: 1101
|
34
34
|
end
|
35
35
|
|
36
|
-
invoice2 =
|
36
|
+
invoice2 = Uomi::generate_invoice do
|
37
37
|
due Time.now - 1.days
|
38
38
|
line_item description: "Line Item 1", amount: 1101
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
Uomi::generate_invoice do
|
42
42
|
due Time.now - 1.days
|
43
43
|
line_item description: "Line Item 1", amount: 0
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
Uomi::Invoice.all.each(&:issue!)
|
47
|
+
Uomi::OverdueInvoice.record_late_payments!
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
invoice2.late_payment.should ==
|
49
|
+
Uomi::LatePayment.count.should == 1
|
50
|
+
Uomi::LatePayment.first.invoice.should == invoice2
|
51
|
+
Uomi::LatePayment.first.amount.should == 1101
|
52
|
+
invoice2.late_payment.should == Uomi::LatePayment.first
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should default the late payment penalty date to 7 days from the date the late payment was recorded" do
|
56
|
-
invoice =
|
56
|
+
invoice = Uomi::generate_invoice do
|
57
57
|
due Time.now - 1.days
|
58
58
|
line_item description: "Line Item 1", amount: 1101
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
Uomi::Invoice.all.each(&:issue!)
|
62
62
|
|
63
|
-
|
63
|
+
Uomi::OverdueInvoice.record_late_payments!
|
64
64
|
invoice.late_payment.penalty_date.should == Date.today.to_time + 7.days
|
65
65
|
end
|
66
66
|
|
data/spec/support/helpers.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Helpers
|
2
2
|
def tear_it_down
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
Uomi::Invoice.delete_all
|
4
|
+
Uomi::LineItem.delete_all
|
5
|
+
Uomi::Transaction.delete_all
|
6
|
+
Uomi::LatePayment.delete_all
|
7
|
+
Uomi::PaymentReference.delete_all
|
8
|
+
Uomi::Seller.delete_all
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "
|
3
|
+
require "uomi/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "uomi"
|
7
|
-
s.version =
|
7
|
+
s.version = Uomi::VERSION
|
8
8
|
s.authors = ["Douglas Anderson", "Jeffrey van Aswegen"]
|
9
9
|
s.email = ["i.am.douglas.anderson@gmail.com", "jeffmess@gmail.com"]
|
10
|
-
s.homepage = 'https://github.com/tehtorq/
|
11
|
-
s.summary = %q{ An
|
10
|
+
s.homepage = 'https://github.com/tehtorq/uomi'
|
11
|
+
s.summary = %q{ An uomi gem. }
|
12
12
|
s.description = %q{ Manage invoices. }
|
13
13
|
|
14
14
|
s.rubyforge_project = "uomi"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uomi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -107,44 +107,44 @@ files:
|
|
107
107
|
- README.md
|
108
108
|
- Rakefile
|
109
109
|
- config.ru
|
110
|
-
- invoicing.gemspec
|
111
|
-
- lib/generators/active_record/invoicing_generator.rb
|
112
110
|
- lib/generators/active_record/templates/migration.rb
|
113
|
-
- lib/
|
114
|
-
- lib/
|
115
|
-
- lib/
|
116
|
-
- lib/
|
117
|
-
- lib/
|
118
|
-
- lib/
|
119
|
-
- lib/
|
120
|
-
- lib/
|
121
|
-
- lib/
|
122
|
-
- lib/
|
123
|
-
- lib/
|
124
|
-
- lib/
|
125
|
-
- lib/
|
126
|
-
- lib/
|
127
|
-
- lib/
|
128
|
-
- lib/
|
129
|
-
- lib/
|
130
|
-
- lib/
|
131
|
-
- lib/
|
132
|
-
- lib/
|
111
|
+
- lib/generators/active_record/uomi_generator.rb
|
112
|
+
- lib/uomi.rb
|
113
|
+
- lib/uomi/buyer.rb
|
114
|
+
- lib/uomi/credit_note.rb
|
115
|
+
- lib/uomi/credit_note_credit_transaction.rb
|
116
|
+
- lib/uomi/credit_note_invoice.rb
|
117
|
+
- lib/uomi/credit_transaction.rb
|
118
|
+
- lib/uomi/debit_transaction.rb
|
119
|
+
- lib/uomi/exception.rb
|
120
|
+
- lib/uomi/invoice.rb
|
121
|
+
- lib/uomi/invoice_adjustment.rb
|
122
|
+
- lib/uomi/invoice_decorator.rb
|
123
|
+
- lib/uomi/invoiceable.rb
|
124
|
+
- lib/uomi/late_payment.rb
|
125
|
+
- lib/uomi/line_item.rb
|
126
|
+
- lib/uomi/line_item_type.rb
|
127
|
+
- lib/uomi/overdue_invoice.rb
|
128
|
+
- lib/uomi/payment_reference.rb
|
129
|
+
- lib/uomi/seller.rb
|
130
|
+
- lib/uomi/transaction.rb
|
131
|
+
- lib/uomi/version.rb
|
133
132
|
- spec/README
|
134
133
|
- spec/internal/config/database.yml.sample
|
135
134
|
- spec/internal/config/routes.rb
|
136
135
|
- spec/internal/db/schema.rb
|
137
136
|
- spec/internal/log/.gitignore
|
138
137
|
- spec/internal/public/favicon.ico
|
139
|
-
- spec/lib/
|
140
|
-
- spec/lib/
|
141
|
-
- spec/lib/
|
142
|
-
- spec/lib/
|
143
|
-
- spec/lib/
|
144
|
-
- spec/lib/
|
138
|
+
- spec/lib/uomi/credit_note_spec.rb
|
139
|
+
- spec/lib/uomi/invoice_adjustment_spec.rb
|
140
|
+
- spec/lib/uomi/invoice_late_payment_spec.rb
|
141
|
+
- spec/lib/uomi/invoice_spec.rb
|
142
|
+
- spec/lib/uomi/line_item_spec.rb
|
143
|
+
- spec/lib/uomi/overdue_invoice_spec.rb
|
145
144
|
- spec/spec_helper.rb
|
146
145
|
- spec/support/helpers.rb
|
147
|
-
|
146
|
+
- uomi.gemspec
|
147
|
+
homepage: https://github.com/tehtorq/uomi
|
148
148
|
licenses: []
|
149
149
|
post_install_message:
|
150
150
|
rdoc_options: []
|
@@ -167,7 +167,7 @@ rubyforge_project: uomi
|
|
167
167
|
rubygems_version: 1.8.24
|
168
168
|
signing_key:
|
169
169
|
specification_version: 3
|
170
|
-
summary: An
|
170
|
+
summary: An uomi gem.
|
171
171
|
test_files:
|
172
172
|
- spec/README
|
173
173
|
- spec/internal/config/database.yml.sample
|
@@ -175,11 +175,11 @@ test_files:
|
|
175
175
|
- spec/internal/db/schema.rb
|
176
176
|
- spec/internal/log/.gitignore
|
177
177
|
- spec/internal/public/favicon.ico
|
178
|
-
- spec/lib/
|
179
|
-
- spec/lib/
|
180
|
-
- spec/lib/
|
181
|
-
- spec/lib/
|
182
|
-
- spec/lib/
|
183
|
-
- spec/lib/
|
178
|
+
- spec/lib/uomi/credit_note_spec.rb
|
179
|
+
- spec/lib/uomi/invoice_adjustment_spec.rb
|
180
|
+
- spec/lib/uomi/invoice_late_payment_spec.rb
|
181
|
+
- spec/lib/uomi/invoice_spec.rb
|
182
|
+
- spec/lib/uomi/line_item_spec.rb
|
183
|
+
- spec/lib/uomi/overdue_invoice_spec.rb
|
184
184
|
- spec/spec_helper.rb
|
185
185
|
- spec/support/helpers.rb
|
data/lib/invoicing/version.rb
DELETED
data/lib/invoicing.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require "active_record"
|
2
|
-
require "workflow"
|
3
|
-
require "invoicing/version"
|
4
|
-
|
5
|
-
module Invoicing
|
6
|
-
|
7
|
-
def self.table_name_prefix
|
8
|
-
'invoicing_'
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.generate(&block)
|
12
|
-
invoice = Invoice.new
|
13
|
-
invoice.instance_eval(&block)
|
14
|
-
invoice.save!
|
15
|
-
invoice
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.generate_credit_note(&block)
|
19
|
-
credit_note = CreditNote.new
|
20
|
-
credit_note.instance_eval(&block)
|
21
|
-
credit_note.save!
|
22
|
-
credit_note.issue!
|
23
|
-
credit_note
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
require "invoicing/exception"
|
29
|
-
require "invoicing/invoiceable"
|
30
|
-
require "invoicing/transaction"
|
31
|
-
require "invoicing/credit_transaction"
|
32
|
-
require "invoicing/debit_transaction"
|
33
|
-
require "invoicing/late_payment"
|
34
|
-
require "invoicing/line_item"
|
35
|
-
require "invoicing/payment_reference"
|
36
|
-
require "invoicing/seller"
|
37
|
-
require "invoicing/buyer"
|
38
|
-
require "invoicing/invoice_decorator"
|
39
|
-
require "invoicing/credit_note_invoice"
|
40
|
-
require "invoicing/credit_note_credit_transaction"
|
41
|
-
|
42
|
-
require "invoicing/invoice"
|
43
|
-
require "invoicing/credit_note"
|
44
|
-
require "invoicing/overdue_invoice"
|
45
|
-
require "invoicing/invoice_adjustment"
|
46
|
-
require "invoicing/line_item_type"
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Invoicing::LineItem do
|
4
|
-
include Helpers
|
5
|
-
|
6
|
-
it "should validate that the amount is positive" do
|
7
|
-
expect {Invoicing::LineItem.create! amount: -0.01}.to raise_error ActiveRecord::RecordInvalid, "Validation failed: Amount must be greater than or equal to 0"
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should validate that the amount is specified" do
|
11
|
-
expect {Invoicing::LineItem.create! amount: nil}.to raise_error ActiveRecord::RecordInvalid, "Validation failed: Amount is not a number, Amount can't be blank"
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|