glasserc / ledger-to-beancount Goto Github PK
View Code? Open in Web Editor NEWAnother Ledger to Beancount converter
Another Ledger to Beancount converter
Hi
Testing with two journals, one is converted while the other one causes an exception. However, reading the trace below I'm not able to understand, which line in journal is the cause?
$ ledger-to-beancount ~/journal.txt
Traceback (most recent call last):
File "/home/ra/.local/share/virtualenvs/ledger-to-beancount-524C-Oyj/bin/ledger-to-beancount", line 11, in <module>
sys.exit(main())
File "/home/ra/.local/share/virtualenvs/ledger-to-beancount-524C-Oyj/lib/python3.6/site-packages/ledger_to_beancount/__main__.py", line 7, in main
output = translate_file(open(filename).readlines())
File "/home/ra/.local/share/virtualenvs/ledger-to-beancount-524C-Oyj/lib/python3.6/site-packages/ledger_to_beancount/__init__.py", line 223, in translate_file
posting = ' {} {}'.format(account, translate_amount(rest))
File "/home/ra/.local/share/virtualenvs/ledger-to-beancount-524C-Oyj/lib/python3.6/site-packages/ledger_to_beancount/__init__.py", line 126, in translate_amount
(amount, units) = parse_amount_and_units(amount)
TypeError: 'NoneType' object is not iterable
The currency formatting could be improved if it could parse and edit the currency in Beancount format.
Just as an example :
2017-07-13 * "Drinks with Friends"
Expenses:Personal:Dave:Beverage:Beer EUR 13.00
Assets:Cash
To as follows:-
2017-07-13 * "Drinks with Friends"
Expenses:Personal:Dave:Beverage:Beer 13.00 EUR
Assets:Cash
You wrote in commit 596e5bf:
Flags are preserved, but since every transaction has to have a flag,
we default to the "*" flag for any unflagged transactions
Actually, that's not true. But if you don't have a flag, you have to write "txn" in beancount. This is documented in the beancount syntax guide.
ledger allows aux dates (date1=date2). The script doesn't know about them:
2018-01-01=2018-01-02 * Opening balance: test
Assets:Test 20.00 EUR
Equity:Opening balance
Noticed that if there's space(s) between the $ sign and the number for an entry, the parser crashes.
Example:
2010-02-04 Purchasing new shoes
Expenses:Clothing $ 100
Liabilities:Credit Card
results in the trace:
Traceback (most recent call last):
File "/Users/hello/.pyenv/versions/3.5.0/bin/ledger-to-beancount", line 9, in <module>
load_entry_point('ledger-to-beancount==0.0.1', 'console_scripts', 'ledger-to-beancount')()
File "/Users/hello/.pyenv/versions/3.5.0/lib/python3.5/site-packages/ledger_to_beancount/__main__.py", line 7, in main
output = translate_file(open(filename).readlines())
File "/Users/hello/.pyenv/versions/3.5.0/lib/python3.5/site-packages/ledger_to_beancount/__init__.py", line 183, in translate_file
posting = ' {} {}'.format(account, translate_amount(rest))
File "/Users/hello/.pyenv/versions/3.5.0/lib/python3.5/site-packages/ledger_to_beancount/__init__.py", line 89, in translate_amount
amount = re.sub(r'\$' + amount_re, partial(replace_number, 'USD'), amount)
File "/Users/hello/.pyenv/versions/3.5.0/lib/python3.5/re.py", line 182, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/Users/hello/.pyenv/versions/3.5.0/lib/python3.5/site-packages/ledger_to_beancount/__init__.py", line 87, in replace_number
amount = Decimal(match.group(1))
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
ledger allows you to specify the total with @@ (rather than the unit price with @). The script
doesn't like this:
2018-01-01 * Opening balance: property
; :opening-balance:
Assets:Property 2 FOO {{ 20.00 EUR}} @@ 20.00 EUR
Equity:Opening balance
File "/home/tbm/.local/lib/python3.5/site-packages/ledger_to_beancount/__init__.py", line 160, in translate_file
(amount, price) = rest.split('@')
ledger requires some commodity names (e.g. those containing numbers) to be quoted but beancount doesn't allow this.
2018-01-01 * Opening balance: test
Assets:Property 2 "FOO" @ 20.00 EUR
Equity:Opening balance
ledger allows lot dates and beancount does as well.
ledger: 2.00 FOO { 4.00 BAR} [2018-03-05}
beancount: 2.00 FOO { 4.00 BAR, 2018-03-05}
But the script gets confused:
2018-01-01 * Opening balance: property
Assets:Property 2 FOO { 20.00 EUR} [2011-12-18] @ 20.00 EUR
Equity:Opening balance
leads to:
File "/home/tbm/.local/lib/python3.5/site-packages/ledger_to_beancount/__init__.py", line 164, in translate_file
number, units = translated_amount.strip().split(' ')
ValueError: too many values to unpack (expected 2)
ledger and beancount allow flags to indicate the status of a transaction. It seems this script ignores
them and puts them in the narration (and puts in a * everywhere as the flag).
2017-12-15 * Gift
Expenses:Gifts 80.00 GBP
Assets:Cash -80.00 GBP
gives:
2017-12-15 * "* Gift"
Note how my flag is in the narration.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.