debitcredit 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0adbf3aea2d75c75e6a73e79ab55714f07ddb76
|
4
|
+
data.tar.gz: 17b30338b6134d6f03b4be289cbbce731f5692a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4508bfa2c7d9d45d5d6bbdda550c9a91922f87ede097a87f2899083f9de20852398646dc30d12ce2d8684097a8ac35fc195c5510738a5debec9a9393c0473d20
|
7
|
+
data.tar.gz: a031a87bfc4d32ff90ff752d9305f62acde430272e041064770decbf8c2de65a9ea0951e9ac4fb4cefbee2a11529999e011cc3b86b1b73769ec854f8914411aa
|
@@ -3,12 +3,16 @@ module Debitcredit
|
|
3
3
|
class Transaction < ActiveRecord::Base
|
4
4
|
belongs_to :reference, polymorphic: true
|
5
5
|
belongs_to :parent_transaction, class_name: 'Debitcredit::Transaction'
|
6
|
+
belongs_to :inverse_transaction, class_name: 'Debitcredit::Transaction'
|
6
7
|
has_many :items, dependent: :destroy, autosave: true
|
7
8
|
|
8
9
|
validates :reference, :description, presence: true
|
9
10
|
validate :ensure_balanced
|
10
11
|
|
12
|
+
validate :parent_not_inversed, if: :is_inverse
|
13
|
+
|
11
14
|
before_create :lock_and_update_balances
|
15
|
+
after_save :save_parent
|
12
16
|
|
13
17
|
def self.prepare(opts = {}, &block)
|
14
18
|
new(opts).tap do |t|
|
@@ -16,10 +20,17 @@ module Debitcredit
|
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
23
|
+
attr_accessor :is_inverse
|
19
24
|
attr_accessor :ignore_overdraft
|
25
|
+
|
20
26
|
def inverse(opts = {})
|
21
|
-
self.class.new({ignore_overdraft: true}.merge(opts)) do |res|
|
27
|
+
self.class.new({ignore_overdraft: true, is_inverse: true}.merge(opts)) do |res|
|
22
28
|
res.items = items.map(&:inverse)
|
29
|
+
res.description ||= "reverse of tr ##{id}: #{description}"
|
30
|
+
res.kind ||= 'rollback'
|
31
|
+
res.reference ||= reference
|
32
|
+
res.parent_transaction = self
|
33
|
+
self.inverse_transaction ||= res
|
23
34
|
end
|
24
35
|
end
|
25
36
|
|
@@ -42,5 +53,13 @@ module Debitcredit
|
|
42
53
|
item.account.lock!.update_balance!(item, !ignore_overdraft)
|
43
54
|
end
|
44
55
|
end
|
56
|
+
|
57
|
+
def save_parent
|
58
|
+
parent_transaction.save! if parent_transaction.try(:inverse_transaction) == self
|
59
|
+
end
|
60
|
+
|
61
|
+
def parent_not_inversed
|
62
|
+
errors.add(:base, :already_inversed) if parent_transaction.inverse_transaction_id
|
63
|
+
end
|
45
64
|
end
|
46
65
|
end
|
data/config/locales/en.yml
CHANGED
data/lib/debitcredit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debitcredit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitaly Kushner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -205,6 +205,7 @@ files:
|
|
205
205
|
- db/migrate/20140128134203_longer_account_name.rb
|
206
206
|
- db/migrate/20140128153104_add_account_overdraft.rb
|
207
207
|
- db/migrate/20140130095257_no_overdraft_by_default.rb
|
208
|
+
- db/migrate/20140612113944_add_inverse_transaction_id.rb
|
208
209
|
- lib/debitcredit/engine.rb
|
209
210
|
- lib/debitcredit/version.rb
|
210
211
|
- lib/debitcredit.rb
|