Skip to content

Commit

Permalink
Merge pull request #221 from sdementen/export_ledger_commodities
Browse files Browse the repository at this point in the history
Export ledger commodities
  • Loading branch information
sdementen authored Jun 17, 2024
2 parents 70f9f29 + fe5c0f1 commit 39ee70f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 54 deletions.
6 changes: 3 additions & 3 deletions piecash/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def ledger(obj, **kwargs):


CURRENCY_RE = re.compile("^[A-Z]{3}$")
NUMBER_RE = re.compile(r"(^|\s+)[-+]?([0-9]*\.[0-9]+|[0-9]+)($|\s+)") # regexp to identify a float with blank spaces
NUMBER_RE = re.compile(r"(^|\s+)[-+]?([0-9]*(\.|,)[0-9]+|[0-9]+)($|\s+)") # regexp to identify a float with blank spaces
NUMERIC_SPACE = re.compile(r"[0-9\s]")
CHARS_ONLY = re.compile(r"[A-Za-z]+")

Expand Down Expand Up @@ -138,7 +138,7 @@ def _(cdty, locale=False, commodity_notes=False, **kwargs):


@ledger.register(Account)
def _(acc, short_account_names=False, **kwargs):
def _(acc, short_account_names=False, locale=False, **kwargs):
"""Return a ledger-cli alike representation of the account"""
# ignore "dummy" accounts
if acc.type is None or acc.parent is None:
Expand All @@ -155,7 +155,7 @@ def _(acc, short_account_names=False, **kwargs):
res += "\tnote {}\n".format(acc.description)

if acc.commodity.is_currency():
res += '\tcheck commodity == "{}"\n'.format(acc.commodity.mnemonic) # .replace('"', '\\"'))
res += '\tcheck commodity == "{}"\n'.format(format_commodity(acc.commodity.mnemonic,locale)) # .replace('"', '\\"'))
return res


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ account Asset:Broker
check commodity == "AED"

account Asset:Broker:Foo stock
check commodity == "FOO"

account Liability
check commodity == "EUR"
Expand All @@ -56,13 +55,10 @@ account Equity:Opening Balances - EUR
check commodity == "EUR"

account Mouvements
check commodity == "FOO"

account Mouvements:NASDAQ
check commodity == "FOO"

account Mouvements:NASDAQ:FOO
check commodity == "FOO"

account Mouvements:CURRENCY
check commodity == "EUR"
Expand Down
4 changes: 0 additions & 4 deletions tests/references/file_template_full.ledger
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ account Asset:Broker
check commodity == "AED"

account Asset:Broker:Foo stock
check commodity == "FOO"

account Liability
check commodity == "EUR"
Expand All @@ -51,13 +50,10 @@ account Equity:Opening Balances - EUR
check commodity == "EUR"

account Mouvements
check commodity == "FOO"

account Mouvements:NASDAQ
check commodity == "FOO"

account Mouvements:NASDAQ:FOO
check commodity == "FOO"

account Mouvements:CURRENCY
check commodity == "EUR"
Expand Down
74 changes: 35 additions & 39 deletions tests/references/file_template_full.locale_True.ledger
Original file line number Diff line number Diff line change
@@ -1,82 +1,78 @@
commodity  ADF
commodity ADF

commodity  AED
commodity AED

commodity  
commodity €

commodity  FOO
commodity FOO

commodity  $US
commodity US$

account Asset
check commodity == "EUR"
check commodity == ""

account Asset:Current
check commodity == "EUR"
check commodity == ""

account Asset:Current:Cash
check commodity == "EUR"
check commodity == ""

account Asset:Current:Savings
check commodity == "EUR"
check commodity == ""

account Asset:Current:Checking
check commodity == "EUR"
check commodity == ""

account Asset:Fixed
check commodity == "EUR"
check commodity == ""

account Asset:Fixed:House
check commodity == "EUR"
check commodity == ""

account Asset:Broker
check commodity == "AED"

account Asset:Broker:Foo stock
check commodity == "FOO"

account Liability
check commodity == "EUR"
check commodity == ""

account Income
check commodity == "EUR"
check commodity == ""

account Expense
check commodity == "EUR"
check commodity == ""

account Equity
check commodity == "EUR"
check commodity == ""

account Equity:Opening Balances - EUR
check commodity == "EUR"
check commodity == ""

account Mouvements
check commodity == "FOO"

account Mouvements:NASDAQ
check commodity == "FOO"

account Mouvements:NASDAQ:FOO
check commodity == "FOO"

account Mouvements:CURRENCY
check commodity == "EUR"
check commodity == ""

account Mouvements:CURRENCY:EUR5
check commodity == "EUR"
check commodity == ""

P 2018-02-21 00:00:00  FOO 0,90 AED
P 2018-02-21 00:00:00  $US 1,40 €
P 2018-02-21 00:00:00  € 1,111111111111111111111111111 AED
P 2018-02-21 00:00:00  ADF 1,50 AED
P 2018-02-21 00:00:00 FOO 0,90 AED
P 2018-02-21 00:00:00 US$ 1,40 €
P 2018-02-21 00:00:00 € 1,111111111111111111111111111 AED
P 2018-02-21 00:00:00 ADF 1,50 AED

2014-12-24 income 1
Income -150,00 €
Asset:Current:Cash 150,00 €

2014-12-24 initial load
Liability -1000,00 €
Asset:Current:Checking 1000,00 €
Liability -1.000,00 €
Asset:Current:Checking 1.000,00 €

2014-12-24 expense 1
Asset:Current:Checking -200,00 €
Expand All @@ -100,20 +96,20 @@ P 2018-02-21 00:00:00  ADF 1,50 AED
Asset:Current:Checking 250,00 €

2018-02-20 Opening Balance
Equity:Opening Balances - EUR -2500,00 €
Asset:Current:Savings 2500,00 €
Equity:Opening Balances - EUR -2.500,00 €
Asset:Current:Savings 2.500,00 €

2018-02-20 house load
Liability -20000,00 €
Asset:Fixed:House 20000,00 €
Liability -20.000,00 €
Asset:Fixed:House 20.000,00 €

2018-02-21 buy foo
Mouvements:NASDAQ:FOO -130,00 FOO @@ 1200,00 €
Asset:Current:Savings -1200,00 €
Asset:Broker:Foo stock 130,00 FOO @@ 1200,00 €
Mouvements:CURRENCY:EUR5 1200,00 €
Mouvements:NASDAQ:FOO -130,00 FOO @@ 1.200,00 €
Asset:Current:Savings -1.200,00 €
Asset:Broker:Foo stock 130,00 FOO @@ 1.200,00 €
Mouvements:CURRENCY:EUR5 1.200,00 €

2018-02-21 Opening Balance
Equity:Opening Balances - EUR -2500,00 €
Asset:Current:Savings 2500,00 €
Equity:Opening Balances - EUR -2.500,00 €
Asset:Current:Savings 2.500,00 €

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ account Broker
check commodity == "AED"

account Foo stock
check commodity == "FOO"

account Liability
check commodity == "EUR"
Expand All @@ -51,13 +50,10 @@ account Opening Balances - EUR
check commodity == "EUR"

account Mouvements
check commodity == "FOO"

account NASDAQ
check commodity == "FOO"

account FOO
check commodity == "FOO"

account CURRENCY
check commodity == "EUR"
Expand Down

0 comments on commit 39ee70f

Please sign in to comment.