Added the option management, and moved the configuration of the default currency, the default account for the income and expenses log, and the recurring expenses and incomes to the options.
This commit is contained in:
@ -19,8 +19,10 @@
|
||||
"""
|
||||
import typing as t
|
||||
|
||||
from accounting import db
|
||||
from accounting.locale import gettext
|
||||
from accounting.models import Account
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
class IncomeExpensesAccount:
|
||||
@ -62,3 +64,20 @@ class IncomeExpensesAccount:
|
||||
account.title = gettext("current assets and liabilities")
|
||||
account.str = account.title
|
||||
return account
|
||||
|
||||
|
||||
def ie_accounts() -> list[IncomeExpensesAccount]:
|
||||
"""Returns accounts for the income and expenses log.
|
||||
|
||||
:return: The accounts for the income and expenses log.
|
||||
"""
|
||||
accounts: list[IncomeExpensesAccount] \
|
||||
= [IncomeExpensesAccount.current_assets_and_liabilities()]
|
||||
accounts.extend([IncomeExpensesAccount(x)
|
||||
for x in db.session.query(Account)
|
||||
.filter(sa.or_(Account.base_code.startswith("11"),
|
||||
Account.base_code.startswith("12"),
|
||||
Account.base_code.startswith("21"),
|
||||
Account.base_code.startswith("22")))
|
||||
.order_by(Account.base_code, Account.no)])
|
||||
return accounts
|
||||
|
@ -63,6 +63,9 @@ data."""
|
||||
__can_edit_func: t.Callable[[], bool] = lambda: True
|
||||
"""The callback that returns whether the current user can edit the accounting
|
||||
data."""
|
||||
__can_admin_func: t.Callable[[], bool] = lambda: True
|
||||
"""The callback that returns whether the current user can administrate the
|
||||
accounting settings."""
|
||||
|
||||
|
||||
def can_view() -> bool:
|
||||
@ -87,6 +90,20 @@ def can_edit() -> bool:
|
||||
return __can_edit_func()
|
||||
|
||||
|
||||
def can_admin() -> bool:
|
||||
"""Returns whether the current user can administrate the accounting
|
||||
settings.
|
||||
|
||||
The user has to log in.
|
||||
|
||||
:return: True if the current user can administrate the accounting settings,
|
||||
or False otherwise.
|
||||
"""
|
||||
if get_current_user() is None:
|
||||
return False
|
||||
return __can_admin_func()
|
||||
|
||||
|
||||
def init_app(bp: Blueprint, user_utils: UserUtilityInterface) -> None:
|
||||
"""Initializes the application.
|
||||
|
||||
@ -94,8 +111,10 @@ def init_app(bp: Blueprint, user_utils: UserUtilityInterface) -> None:
|
||||
:param user_utils: The user utilities.
|
||||
:return: None.
|
||||
"""
|
||||
global __can_view_func, __can_edit_func
|
||||
global __can_view_func, __can_edit_func, __can_admin_func
|
||||
__can_view_func = user_utils.can_view
|
||||
__can_edit_func = user_utils.can_edit
|
||||
__can_admin_func = user_utils.can_admin
|
||||
bp.add_app_template_global(user_utils.can_view, "accounting_can_view")
|
||||
bp.add_app_template_global(user_utils.can_edit, "accounting_can_edit")
|
||||
bp.add_app_template_global(user_utils.can_admin, "accounting_can_admin")
|
||||
|
@ -50,6 +50,15 @@ class UserUtilityInterface(t.Generic[T], ABC):
|
||||
data, or False otherwise.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def can_admin(self) -> bool:
|
||||
"""Returns whether the currently logged-in user can administrate the
|
||||
accounting settings.
|
||||
|
||||
:return: True if the currently logged-in user can administrate the
|
||||
accounting settings, or False otherwise.
|
||||
"""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def cls(self) -> t.Type[T]:
|
||||
|
Reference in New Issue
Block a user