Skip to content

Commit f10cfd6

Browse files
Eric ForgyEric Forgy
Eric Forgy
authored and
Eric Forgy
committed
Update
- Use new convenience positions: USD - Remove imports (use explicit module names)
1 parent 9e14a49 commit f10cfd6

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

Project.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ keywords = ["Finance", "Ledger"]
44
license = "MIT"
55
desc = "Financial ledgers"
66
authors = ["Eric Forgy <[email protected]>", "ScottPJones <[email protected]>"]
7-
version = "0.3.0"
7+
version = "0.4.0"
88

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

1617
[compat]
17-
Assets = "0.8"
18-
Instruments = "0.7"
18+
Assets = "0.10"
19+
Currencies = "0.18"
20+
Instruments = "0.9"
1921

2022
[extras]
2123
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/Ledgers.jl

+11-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ Licensed under MIT License, see LICENSE.md
1212
module Ledgers
1313

1414
using UUIDs, StructArrays, AbstractTrees
15-
using Instruments
16-
import Instruments: instrument, symbol, amount, name, currency
15+
using Assets, Instruments, Currencies
1716

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

8180
function AccountGroup(
82-
::P,
81+
::Type{P},
8382
code,
8483
name,
8584
isdebit=true;
@@ -131,11 +130,17 @@ subgroups(group::AccountGroup) = group.subgroups
131130

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

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

136-
currency(::AccountType{P}) where {P <: Position} = currency(P)
135+
Instruments.symbol(::AccountType{P}) where {I,P <: Position{I}} = symbol(I)
137136

138-
amount(acc::AccountType) = amount(balance(acc))
137+
Instruments.currency(::AccountType{P}) where {I,P <: Position{I}} = currency(I)
138+
139+
Instruments.instrument(::AccountType{P}) where {I,P <: Position{I}} = instrument(I)
140+
141+
Instruments.position(::AccountType{P}) where {I,P <: Position{I}} = position(I)
142+
143+
Instruments.amount(acc::AccountType) = amount(balance(acc))
139144

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

test/runtests.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ using Ledgers, Test
22
using Assets: USD
33

44
function example()
5-
group = AccountGroup(0USD, AccountCode("0000000"), "Account Group", true)
6-
assets = AccountGroup(0USD, AccountCode("1000000"), "Assets", true, parent=group)
7-
liabilities = AccountGroup(0USD, AccountCode("2000000"), "Liabilities", false, parent=group)
5+
group = AccountGroup(USD, AccountCode("0000000"), "Account Group", true)
6+
assets = AccountGroup(USD, AccountCode("1000000"), "Assets", true, parent=group)
7+
liabilities = AccountGroup(USD, AccountCode("2000000"), "Liabilities", false, parent=group)
88
cash = AccountInfo(Account(0USD), AccountCode("1010000"), "Cash", true, parent=assets)
99
payable = AccountInfo(Account(0USD), AccountCode("2010000"), "Accounts Payable", false, parent=liabilities)
1010

0 commit comments

Comments
 (0)