From f10cfd600be45ab7304fcffe435b268f165346be Mon Sep 17 00:00:00 2001 From: Eric Forgy Date: Sat, 4 Jul 2020 22:31:01 -0700 Subject: [PATCH] Update - Use new convenience positions: USD - Remove imports (use explicit module names) --- Project.toml | 8 +++++--- src/Ledgers.jl | 17 +++++++++++------ test/runtests.jl | 6 +++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Project.toml b/Project.toml index 538f9b1..c2a468e 100644 --- a/Project.toml +++ b/Project.toml @@ -4,18 +4,20 @@ keywords = ["Finance", "Ledger"] license = "MIT" desc = "Financial ledgers" authors = ["Eric Forgy ", "ScottPJones "] -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" diff --git a/src/Ledgers.jl b/src/Ledgers.jl index 2413319..5387b31 100644 --- a/src/Ledgers.jl +++ b/src/Ledgers.jl @@ -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 @@ -79,7 +78,7 @@ struct AccountGroup{P <: Position} <: AccountNode{P} end function AccountGroup( - ::P, + ::Type{P}, code, name, isdebit=true; @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 50ed1bb..2ee9170 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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)