Coder Social home page Coder Social logo

daniel-wells / beancount_balancechange Goto Github PK

View Code? Open in Web Editor NEW
7.0 7.0 0.0 30 KB

A Beancount plugin that performs an assertion (check) on the change in balance between two dates.

License: GNU General Public License v2.0

Python 100.00%
beancount

beancount_balancechange's People

Contributors

daniel-wells avatar natrbro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

beancount_balancechange's Issues

Plugin explodes after processing a small number (2?) of Txns [bug]

Hey there - thanks for writing this plugin; it's exactly what I'm looking for!

I've got a non-trivial setup that I've installed the plugin into via the option "insert_pythonpath" "True" method. I.e. I've simply curl'd the plugin (at commit ee182fe2c703343969ec4fb396ae7e40ff2c2484) into a subdir of my setup, which I mention solely to explain the slightly non-standard invocation you might see later in this Issue :-) Hopefully that's not related to the underlying problem - I've validated that the plugin is being invoked, and can demonstrate that if your hunch is User Error ... :-)

I've managed to reduce the journal that creates this error down to quite a small reproducer. Here's the content, and the shell session in action. I've added 2 lines to the plugin, for debugging:

  • each Txn gets print(entry)'d as it starts being processed
  • the line that might explode is executed
  • DONE is printed if the line (update_t1_amounts(entry, t1_amounts, real_root)) doesn't explode.

This should demonstrate both the explosion, and the context in which it happens. It /seems/ to explode on the 2nd Txn it encounters, which I see when commenting out the 2.98GBP Txn, below, and then observing the 7.39GBP Txn explode in its place.

Any ideas?

$ bean-check --version
Beancount 2.3.5
$ python -V
Python 3.9.2
$ find . -type f
./plugins/balance_change.py
./test.beancount
$ cat test.beancount 

option "operating_currency" "GBP"
option "insert_pythonpath" "True"

plugin "beancount.plugins.auto_accounts"
plugin "plugins.balance_change"

2020-11-03 custom "balance_change" Expenses:WebHosting 7.39 GBP
        since: 2020-11-01

2020-11-02 * "Amazon" "Book" #ctax
        Liabilities:OutOfPocketExpenses               -1.98 GBP
        Expenses:BooksAndJournals:Books:Digital        1.98 GBP

2020-11-02 * "Amazon" "Book" #ctax
        Liabilities:OutOfPocketExpenses               -2.98 GBP
        Expenses:BooksAndJournals:Books:Physical       2.98 GBP

2020-11-02 * "Gandi" "Domain" #ctax
        Liabilities:OutOfPocketExpenses               -7.39 GBP
        Expenses:WebHosting                            7.39 GBP

$ bean-check test.beancount 
Transaction(meta={'filename': '/home/user/code/company-beancount/tmp/plugin-bug/test.beancount', 'lineno': 11, '__tolerances__': {'GBP': Decimal('0.005')}}, date=datetime.date(2020, 11, 2), flag='*', payee='Amazon', narration='Book', tags=frozenset({'ctax'}), links=frozenset(), postings=[Posting(account='Liabilities:OutOfPocketExpenses', units=-1.98 GBP, cost=None, price=None, flag=None, meta={'filename': '/home/user/code/company-beancount/tmp/plugin-bug/test.beancount', 'lineno': 12}), Posting(account='Expenses:BooksAndJournals:Books:Digital', units=1.98 GBP, cost=None, price=None, flag=None, meta={'filename': '/home/user/code/company-beancount/tmp/plugin-bug/test.beancount', 'lineno': 13})])
DONE
Transaction(meta={'filename': '/home/user/code/company-beancount/tmp/plugin-bug/test.beancount', 'lineno': 15, '__tolerances__': {'GBP': Decimal('0.005')}}, date=datetime.date(2020, 11, 2), flag='*', payee='Amazon', narration='Book', tags=frozenset({'ctax'}), links=frozenset(), postings=[Posting(account='Liabilities:OutOfPocketExpenses', units=-2.98 GBP, cost=None, price=None, flag=None, meta={'filename': '/home/user/code/company-beancount/tmp/plugin-bug/test.beancount', 'lineno': 16}), Posting(account='Expenses:BooksAndJournals:Books:Physical', units=2.98 GBP, cost=None, price=None, flag=None, meta={'filename': '/home/user/code/company-beancount/tmp/plugin-bug/test.beancount', 'lineno': 17})])
<load>:0:       Error applying plugin "plugins.balance_change": Traceback (most recent call last):
    File "/home/user/.cache/pypoetry/virtualenvs/company-beancount-_c2fM7v6-py3.9/lib/python3.9/site-packages/beancount/loader.py", line 602, in run_transformations
      entries, plugin_errors = callback(entries, options_map, *args)
    File "/home/user/code/company-beancount/tmp/plugin-bug/plugins/balance_change.py", line 107, in balance_change
      update_t1_amounts(entry, t1_amounts, real_root)
    File "/home/user/code/company-beancount/tmp/plugin-bug/plugins/balance_change.py", line 89, in update_t1_amounts
      entries_to_sum = [k for k,v in t1_amounts.items() if v == "NaN" and entry.date >= k[1]]
    File "/home/user/code/company-beancount/tmp/plugin-bug/plugins/balance_change.py", line 89, in <listcomp>
      entries_to_sum = [k for k,v in t1_amounts.items() if v == "NaN" and entry.date >= k[1]]
    File "/home/user/.cache/pypoetry/virtualenvs/company-beancount-_c2fM7v6-py3.9/lib/python3.9/site-packages/beancount/core/amount.py", line 90, in __eq__
      return (self.number, self.currency) == (other.number, other.currency)
  AttributeError: 'str' object has no attribute 'number'

Thanks again for publishing this plugin! ๐Ÿ˜„ โค๏ธ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.