Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
- Use new convenience positions: USD
- Remove imports (use explicit module names)
  • Loading branch information
EricForgy committed Jul 5, 2020
1 parent 9e14a49 commit f10cfd6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
8 changes: 5 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ keywords = ["Finance", "Ledger"]
license = "MIT"
desc = "Financial ledgers"
authors = ["Eric Forgy <[email protected]>", "ScottPJones <[email protected]>"]
version = "0.3.0"
version = "0.4.0"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Assets = "821ac057-2368-47e2-a1d8-2c0798f0e233"
Currencies = "0fd90b74-7c1f-579e-9252-02cd883047b9"
Instruments = "2a4f3d17-849a-48a1-809e-d780c70a95a0"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Assets = "0.8"
Instruments = "0.7"
Assets = "0.10"
Currencies = "0.18"
Instruments = "0.9"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
17 changes: 11 additions & 6 deletions src/Ledgers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ Licensed under MIT License, see LICENSE.md
module Ledgers

using UUIDs, StructArrays, AbstractTrees
using Instruments
import Instruments: instrument, symbol, amount, name, currency
using Assets, Instruments, Currencies

export Account, Ledger, Entry, Identifier, AccountId, AccountCode, AccountInfo, AccountGroup
export id, balance, credit!, debit!, post!, instrument, currency, symbol, amount
Expand Down Expand Up @@ -79,7 +78,7 @@ struct AccountGroup{P <: Position} <: AccountNode{P}
end

function AccountGroup(
::P,
::Type{P},
code,
name,
isdebit=true;
Expand Down Expand Up @@ -131,11 +130,17 @@ subgroups(group::AccountGroup) = group.subgroups

instrument(::AccountType{P}) where {P <: Position} = instrument(P)

symbol(::AccountType{P}) where {P <: Position} = symbol(P)
# import Instruments: symbol, currency, instrument, position, amount

currency(::AccountType{P}) where {P <: Position} = currency(P)
Instruments.symbol(::AccountType{P}) where {I,P <: Position{I}} = symbol(I)

amount(acc::AccountType) = amount(balance(acc))
Instruments.currency(::AccountType{P}) where {I,P <: Position{I}} = currency(I)

Instruments.instrument(::AccountType{P}) where {I,P <: Position{I}} = instrument(I)

Instruments.position(::AccountType{P}) where {I,P <: Position{I}} = position(I)

Instruments.amount(acc::AccountType) = amount(balance(acc))

debit!(acc::Account, amt::Position) = (acc.balance += amt)

Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ using Ledgers, Test
using Assets: USD

function example()
group = AccountGroup(0USD, AccountCode("0000000"), "Account Group", true)
assets = AccountGroup(0USD, AccountCode("1000000"), "Assets", true, parent=group)
liabilities = AccountGroup(0USD, AccountCode("2000000"), "Liabilities", false, parent=group)
group = AccountGroup(USD, AccountCode("0000000"), "Account Group", true)
assets = AccountGroup(USD, AccountCode("1000000"), "Assets", true, parent=group)
liabilities = AccountGroup(USD, AccountCode("2000000"), "Liabilities", false, parent=group)
cash = AccountInfo(Account(0USD), AccountCode("1010000"), "Cash", true, parent=assets)
payable = AccountInfo(Account(0USD), AccountCode("2010000"), "Accounts Payable", false, parent=liabilities)

Expand Down

0 comments on commit f10cfd6

Please sign in to comment.