Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.5.3.1 #143

Merged
merged 10 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ More details available in the [Django Ledger v0.5 Page](https://www.arrobalytics

### Version 0.6

* IO Digest Context Manager
* Credit Line Models.
* Time tracking.
* Transaction tagging.
Expand Down
2 changes: 1 addition & 1 deletion django_ledger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
default_app_config = 'django_ledger.apps.DjangoLedgerConfig'

"""Django Ledger"""
__version__ = '0.5.3.0'
__version__ = '0.5.3.1'
__license__ = 'GPLv3 License'

__author__ = 'Miguel Sanda'
Expand Down
294 changes: 129 additions & 165 deletions django_ledger/io/data_generator.py

Large diffs are not rendered by default.

21 changes: 18 additions & 3 deletions django_ledger/io/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import sys
from itertools import chain
from typing import Set
from typing import Set, List, Union

from django.utils.translation import gettext as _

Expand Down Expand Up @@ -609,10 +609,25 @@
GROUPS_DIRECTORY[group] = getattr(mod, group)


def validate_roles(roles) -> Set[str]:
def validate_roles(roles: Union[str, List[str]], raise_exception: bool = True) -> Set[str]:
"""
Validates a given role identifier against the valid role available.
Parameters
----------
roles: str or list
The role or list of roles to validate.
raise_exception: bool
Raises InvalidRoleError if any of the roles provided if not valid.

Returns
-------
set
A set of the valid roles.
"""
if isinstance(roles, str):
roles = set(roles)
for r in roles:
if r not in VALID_ROLES:
raise InvalidRoleError('{rls}) is invalid. Choices are {ch}'.format(ch=', '.join(VALID_ROLES), rls=r))
if raise_exception:
raise InvalidRoleError('{rls}) is invalid. Choices are {ch}'.format(ch=', '.join(VALID_ROLES), rls=r))
return set(roles)
5 changes: 4 additions & 1 deletion django_ledger/models/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def with_roles(self, roles: Union[List, str]):
roles = validate_roles(roles)
return self.filter(role__in=roles)

def expenses(self):
return self.filter(role__in=GROUP_EXPENSES)

def is_coa_root(self):
return self.filter(role__in=ROOT_GROUP)

Expand Down Expand Up @@ -139,7 +142,7 @@ def gb_bs_role(self):
]

def is_role_default(self):
return self.filter(role_default=True)
return self.not_coa_root().filter(role_default=True)


class AccountModelManager(MP_NodeManager):
Expand Down
2 changes: 2 additions & 0 deletions django_ledger/models/bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ def configure(self,
ledger_model.name = ledger_name

ledger_model.clean()
ledger_model.clean_fields()

self.ledger = ledger_model

Expand All @@ -480,6 +481,7 @@ def configure(self,
self.generate_bill_number(commit=commit)

self.clean()
self.clean_fields()

if commit:
self.save()
Expand Down
16 changes: 10 additions & 6 deletions django_ledger/models/coa_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@

]


def get_default_coa() -> List[Dict]:
if DJANGO_LEDGER_DEFAULT_COA is not None and isinstance(DJANGO_LEDGER_DEFAULT_COA, list):
return DJANGO_LEDGER_DEFAULT_COA
return DEFAULT_CHART_OF_ACCOUNTS


if DJANGO_LEDGER_DEFAULT_COA:
DJANGO_LEDGER_DEFAULT_COA = get_default_coa()

PREFIX_MAP = {
'in': ROOT_INCOME,
'ex': ROOT_EXPENSES,
Expand Down Expand Up @@ -337,12 +347,6 @@ def verify_unique_code():
raise DjangoLedgerConfigurationError('Default CoA is not unique.')


def get_default_coa() -> List[Dict]:
if DJANGO_LEDGER_DEFAULT_COA is not None and isinstance(DJANGO_LEDGER_DEFAULT_COA, list):
return DJANGO_LEDGER_DEFAULT_COA
return DEFAULT_CHART_OF_ACCOUNTS


def get_default_coa_rst(default_coa: Optional[Dict] = None) -> str:
"""
Converts the provided Chart of Account into restructuredText format.
Expand Down
Loading