adamcharnock / django-hordak

Double entry accounting in Django
http://django-hordak.readthedocs.io
MIT License
231 stars 55 forks source link

Account default CURRENCIES warning #78

Closed nitsujri closed 1 year ago

nitsujri commented 1 year ago

Thanks for this great repo! Continuing my journey to using this. This is very low priority.

Based on the documentation for CURRENCIES the form is supposed to be:

# settings.py
CURRENCIES = ['SGD', 'IDR']

But when I do this I get the warning:

./manage.py makemigrations
System check identified some issues:

WARNINGS:
hordak.Account.currencies: (fields.E010) ArrayField default should be a callable instead of an instance so that it's not shared between all field instances.
    HINT: Use a callable instead, e.g., use `list` instead of `[]`.

Which then leads me to change CURRENCIES:

def currencies():
    return ["SGD", "IDR"]
CURRENCIES = currencies

Now the warning disappears, yay! But now that it is a callable function instead of an iterable, this breaks:

# https://github.com/adamcharnock/django-hordak/blob/master/hordak/forms/transactions.py#L46
if code == default_currency or code in CURRENCIES

A quick test (i'm pretty new, so needed to manually test):

>>> def currencies():
...     return ["SGD", "IDR"]
...
>>> currencies()
['SGD', 'IDR']
>>> 'SGD' in currencies
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument of type 'function' is not iterable

Any recommendation around this warning?

nitsujri commented 1 year ago

@PetrDlouhy thanks so much! this has been fixed by the latest update. super happy to remove that warning!