ledger_accountable 0.0.3.pre → 0.0.5.pre

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5072aa4e2db505396bb59a25bbc5ab2fb40e30b0286002b232f988554fc1167b
4
- data.tar.gz: 7a213bbaa196aaa6e8225aa9f0e6f1e4af81ce686b4a4b2a835d279eb424b09e
3
+ metadata.gz: a4d8258d74e78940001a6017772df0823788a51a4d7351776e8da084ec1e1a49
4
+ data.tar.gz: a798ff75abf3860b1a12e62e6eb9e51d53cc7210f7cdd8da8f33aa880ff86637
5
5
  SHA512:
6
- metadata.gz: 0a36f896a3dc8ae48e1933d33e44de9e350daf57570b46a832144fb512538a2bf5ad7bc9cecdd79b2f0099413a82d81acb534ec1636b7d26006c087832a92d3a
7
- data.tar.gz: ea0fb2fcb902883acb6f6cd7e45b07e214ed771f2d56bd0389f754bb99ee371a2016081bdc255f44ef61954fe3205fbb2297c2bf71c154cfbef4ea660fb87301
6
+ metadata.gz: 37f453f5fbcd0203b46fae44f3e064b725bff016f7e9da79111bd29b7a46a9c1654056be9f235c68127659f68884bba2c224bc50b8f5da309629b14ff013ee2c
7
+ data.tar.gz: 60a703495fe59638a5d48bd1596eaf15707d37970c050d7c2375e5267270d2502fc967809b04c3b74957115e63fe7f69d47751392cbbd1424f42d6f1d4650783
@@ -9,7 +9,7 @@ class LedgerEntry < ApplicationRecord
9
9
 
10
10
  store :metadata, coder: JSON
11
11
 
12
- validates :amount, presence: true
12
+ validates :amount_cents, presence: true
13
13
  validates :entry_type, presence: true
14
14
 
15
15
  def to_itemized_s(line_type = :line)
@@ -4,7 +4,7 @@ class CreateLedgerEntries < ActiveRecord::Migration[6.1]
4
4
  t.references :owner, polymorphic: true, null: false
5
5
  t.references :ledger_item, polymorphic: true, null: false
6
6
  t.integer :entry_type, null: false
7
- t.decimal :amount, precision: 10, scale: 2, default: 0.0, null: false
7
+ t.integer :amount_cents, default: 0, null: false
8
8
  t.text :metadata
9
9
 
10
10
  t.timestamps
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LedgerAccountable
4
- VERSION = "0.0.3.pre".freeze
4
+ VERSION = "0.0.5.pre".freeze
5
5
  end
@@ -153,7 +153,7 @@ module LedgerAccountable
153
153
  raise NotImplementedError, "Implement #{self.class.ledger_amount_attribute} in #{self.class.name}"
154
154
  end
155
155
 
156
- ledger_amount_multiplier = self.class.ledger_type == :debit ? 1 : -1
156
+ ledger_amount_multiplier = self.class.ledger_type == :credit ? 1 : -1
157
157
  ledger_amount_multiplier * (send(self.class.ledger_amount_attribute) || 0.0)
158
158
  end
159
159
 
@@ -161,7 +161,7 @@ module LedgerAccountable
161
161
  # stored on the LedgerAccountable object
162
162
  def net_ledger_amount
163
163
  previous_ledger_amount = attribute_was(self.class.ledger_amount_attribute)
164
- ledger_amount_multiplier = self.class.ledger_type == :debit ? 1 : -1
164
+ ledger_amount_multiplier = self.class.ledger_type == :credit ? 1 : -1
165
165
  ledger_amount_multiplier * (ledger_amount - (previous_ledger_amount || 0.0))
166
166
  end
167
167
 
@@ -286,7 +286,7 @@ module LedgerAccountable
286
286
  owner: owner,
287
287
  ledger_item: self,
288
288
  entry_type: entry_type,
289
- amount: amount,
289
+ amount_cents: amount,
290
290
  metadata: metadata
291
291
  )
292
292
  rescue ActiveRecord::RecordInvalid => e
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ledger_accountable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.pre
4
+ version: 0.0.5.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendan Maclean