accounting.utils package
Submodules
accounting.utils.cast module
The utilities to cast values into desired types, to avoid IDE warnings.
This module should not import any other module from the application.
- accounting.utils.cast.s(message: Any) str
Casts the LazyString message to the string type.
- Parameters:
message – The message.
- Returns:
The binary expression itself.
accounting.utils.current_account module
The current assets and liabilities account.
- class accounting.utils.current_account.CurrentAccount(account: Account | None = None)
Bases:
object
A current assets and liabilities account.
- CURRENT_AL_CODE: str = '0000-000'
The account code for all current assets and liabilities.
- classmethod accounts() list[Self]
Returns the current assets and liabilities accounts.
- Returns:
The current assets and liabilities accounts.
- code: str
The code.
- classmethod current_assets_and_liabilities() Self
Returns the pseudo account for all current assets and liabilities.
- Returns:
The pseudo account for all current assets and liabilities.
- id: int
The ID.
- classmethod sql_condition() BinaryExpression
Returns the SQL condition for the current assets and liabilities accounts.
- Returns:
The SQL condition for the current assets and liabilities accounts.
- str: str
The string representation of the account.
- title: str
The title.
accounting.utils.flash_errors module
The utility to flash all errors from the forms.
This module should not import any other module from the application.
- accounting.utils.flash_errors.flash_form_errors(form: FlaskForm) None
Flash all errors from a form recursively.
- Parameters:
form – The form.
- Returns:
None.
accounting.utils.journal_entry_types module
The journal entry types.
- class accounting.utils.journal_entry_types.JournalEntryType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
The journal entry types.
- CASH_DISBURSEMENT: str = 'disbursement'
The cash disbursement journal entry.
- CASH_RECEIPT: str = 'receipt'
The cash receipt journal entry.
- TRANSFER: str = 'transfer'
The transfer journal entry.
accounting.utils.next_uri module
The utilities to handle the next URI.
This module should not import any other module from the application.
- accounting.utils.next_uri.append_next(uri: str) str
Appends the current URI as the next URI to the query argument.
- Parameters:
uri – The URI.
- Returns:
The URI with the current URI appended as the next URI.
- accounting.utils.next_uri.decode_next(uri: str) str
Decodes the encoded next URI.
- Parameters:
uri – The encoded next URI.
- Returns:
The next URI.
- accounting.utils.next_uri.encode_next(uri: str) str
Encodes the next URI.
- Parameters:
uri – The next URI.
- Returns:
The encoded next URI.
- accounting.utils.next_uri.inherit_next(uri: str) str
Inherits the current next URI to the query argument, if exists.
- Parameters:
uri – The URI.
- Returns:
The URI with the current next URI added at the query argument.
- accounting.utils.next_uri.init_app(bp: Blueprint) None
Initializes the application.
- Parameters:
bp – The blueprint of the accounting application.
- Returns:
None.
- accounting.utils.next_uri.or_next(uri: str) str
Returns the next URI, if exists, or the supplied URI.
- Parameters:
uri – The URI.
- Returns:
The next URI or the supplied URI.
accounting.utils.offset_alias module
The SQLAlchemy alias for the offset items.
- accounting.utils.offset_alias.offset_alias() Alias
Returns the SQLAlchemy alias for the offset items.
- Returns:
The SQLAlchemy alias for the offset items.
accounting.utils.options module
The getter and setter for the option management.
- class accounting.utils.options.Options
Bases:
object
The options.
- commit() None
Commits the options to the database.
- Returns:
None.
- property default_currency_code: str
Returns the default currency code.
- Returns:
The default currency code.
- property default_ie_account: CurrentAccount
Returns the default account for the income and expenses log.
- Returns:
The default account for the income and expenses log.
- property default_ie_account_code: str
Returns the default account code for the income and expenses log.
- Returns:
The default account code for the income and expenses log.
- is_modified: bool
Whether the options were modified.
- property recurring: Recurring
Returns the recurring expenses and incomes.
- Returns:
The recurring expenses and incomes.
- property recurring_data: dict[str, list[tuple[str, str, str]]]
Returns the data of the recurring expenses and incomes.
- Returns:
The data of the recurring expenses and incomes.
- class accounting.utils.options.Recurring(data: dict[str, list[tuple[str, str, str]]])
Bases:
object
The recurring expenses or incomes.
- property codes: set[str]
Returns all the account codes.
- Returns:
All the account codes.
- expenses: list[RecurringItem]
The recurring expenses.
- incomes: list[RecurringItem]
The recurring incomes.
- class accounting.utils.options.RecurringItem(name: str, account_code: str, description_template: str)
Bases:
object
A recurring item.
- account_code: str
The account code.
- property account_text: str
Returns the account text.
- Returns:
The account text.
- description_template: str
The description template.
- name: str
The name.
accounting.utils.pagination module
The pagination utilities.
This module should not import any other module from the application.
- class accounting.utils.pagination.AbstractPagination
Bases:
Generic
[T
]An abstract pagination.
- is_paged: bool
Whether there should be pagination.
- page_size: int
The number of items in a page.
- accounting.utils.pagination.DEFAULT_PAGE_SIZE: int = 10
The default page size.
- class accounting.utils.pagination.EmptyPagination
Bases:
AbstractPagination
[T
]The pagination from empty data.
- class accounting.utils.pagination.Link(text: str, uri: str | None = None, is_current: bool = False, is_for_mobile: bool = False)
Bases:
object
A link.
- is_current: bool
Whether the link is the current page.
- is_for_mobile: bool
Whether the link should be shown on mobile screens.
- text: str
The link text
- uri: str | None
The link URI, or None if there is no link.
- class accounting.utils.pagination.NonEmptyPagination(items: list[T], is_reversed: bool = False)
Bases:
AbstractPagination
[T
]The pagination with real data.
- PAGE_SIZE_OPTION_VALUES: list[int] = [10, 100, 200]
The page size options.
- class accounting.utils.pagination.Pagination(items: list[T], is_reversed: bool = False)
Bases:
Generic
[T
]The pagination utility.
- is_paged: bool
Whether there should be pagination.
- page_size: int
The number of items in a page.
- exception accounting.utils.pagination.Redirection(new_url: str)
Bases:
RequestRedirect
The redirection.
- code: int | None = 302
The HTTP code.
- class accounting.utils.pagination.T
The pagination item type.
alias of TypeVar(‘T’)
accounting.utils.permission module
The permissions.
This module should not import any other module from the application.
- accounting.utils.permission.can_admin() bool
Returns whether the current user can administrate the accounting settings.
The user has to log in.
- Returns:
True if the current user can administrate the accounting settings, or False otherwise.
- accounting.utils.permission.can_edit() bool
Returns whether the current user can edit the accounting data.
The user has to log in.
- Returns:
True if the current user can edit the accounting data, or False otherwise.
- accounting.utils.permission.can_view() bool
Returns whether the current user can view the accounting data.
- Returns:
True if the current user can view the accounting data, or False otherwise.
- accounting.utils.permission.has_permission(rule: Callable[[], bool]) Callable
The permission decorator to check whether the current user is allowed.
- Parameters:
rule – The permission rule.
- Returns:
The view decorator.
- accounting.utils.permission.init_app(bp: Blueprint, user_utils: UserUtilityInterface) None
Initializes the application.
- Parameters:
bp – The blueprint of the accounting application.
user_utils – The user utilities.
- Returns:
None.
accounting.utils.query module
The query keyword parser.
This module should not import any other module from the application.
- accounting.utils.query.parse_query_keywords(q: str | None) list[str]
Returns the query keywords by the query parameter.
- Parameters:
q – The query parameter.
- Returns:
The query keywords.
accounting.utils.random_id module
The random ID utility for the data models.
This module should not import any other module from the application.
- accounting.utils.random_id.new_id(cls: Type[Model])
Generates and returns a new, unused random ID for the data model.
- Parameters:
cls – The data model.
- Returns:
The newly-generated, unused random ID.
accounting.utils.strip_text module
The text stripper for the form fields.
This module should not import any other module from the application.
- accounting.utils.strip_text.strip_multiline_text(s: str | None) str | None
The filter to strip a piece of multi-line text.
- Parameters:
s – The text input string.
- Returns:
The filtered string.
- accounting.utils.strip_text.strip_text(s: str | None) str | None
The filter to strip the leading and trailing white spaces of text.
- Parameters:
s – The text input string.
- Returns:
The filtered string.
accounting.utils.title_case module
The title case capitalization for the base account titles. This follows the APA style title case capitalization. See https://apastyle.apa.org/style-grammar-guidelines/capitalization/title-case .
This module should not import any other module from the application.
- accounting.utils.title_case.ARTICLES: set[str] = {'a', 'an', 'the'}
Articles.
- accounting.utils.title_case.CONJUNCTIONS: set[str] = {'and', 'as', 'but', 'for', 'if', 'nor', 'or', 'so', 'yet'}
Short conjunctions.
- accounting.utils.title_case.MINOR_WORDS: set[str] = {'a', 'an', 'and', 'as', 'at', 'but', 'for', 'if', 'in', 'nor', 'of', 'on', 'or', 'per', 'so', 'the', 'to', 'up', 'via', 'yet'}
Minor words that should be in lowercase.
- accounting.utils.title_case.PREPOSITIONS: set[str] = {'as', 'at', 'by', 'for', 'in', 'of', 'on', 'per', 'to', 'up', 'via'}
Short prepositions.
- accounting.utils.title_case.title_case(s: str) str
Capitalize a title string for the base account titles. Do not use it in other places. This excludes “by” as in “1223 by-products”.
- Parameters:
s – The title string.
- Returns:
The capitalized title string.
accounting.utils.user module
The user utilities.
This module should not import any other module from the application.
- class accounting.utils.user.T
The user data model data type.
alias of TypeVar(‘T’, bound=
Model
)
- class accounting.utils.user.UserUtilityInterface
Bases:
Generic
[T
],ABC
The interface for the user utilities.
- abstract can_admin() bool
Returns whether the currently logged-in user can administrate the accounting settings.
- Returns:
True if the currently logged-in user can administrate the accounting settings, or False otherwise.
- abstract can_edit() bool
Returns whether the currently logged-in user can edit the accounting data.
- Returns:
True if the currently logged-in user can edit the accounting data, or False otherwise.
- abstract can_view() bool
Returns whether the currently logged-in user can view the accounting data.
- Returns:
True if the currently logged-in user can view the accounting data, or False otherwise.
- abstract property cls: Type[T]
Returns the class of the user data model.
- Returns:
The class of the user data model.
- abstract property current_user: T | None
Returns the currently logged-in user.
- Returns:
The currently logged-in user, or None if the user has not logged in
- abstract get_by_username(username: str) T | None
Returns the user by her username.
- Returns:
The user by her username, or None if the user was not found.
- abstract get_pk(user: T) int
Returns the primary key of the user, as an integer.
- Returns:
The primary key of the user, as an integer.
- abstract property pk_column: Column
Returns the primary key column.
- Returns:
The primary key column.
- abstract unauthorized() Response | None
Returns the response to require the user to log in.
This may be a redirection to the login page, or an HTTP 401 Unauthorized response for HTTP Authentication. If this returns None, an HTTP 403 Forbidden response is return to the user.
- Returns:
The response to require the user to log in.
- accounting.utils.user.get_current_user() Model | None
Returns the currently logged-in user. The result is cached in the current request.
- Returns:
The currently logged-in user.
- accounting.utils.user.get_current_user_pk() int
Returns the primary key value of the currently logged-in user.
- Returns:
The primary key value of the currently logged-in user.
- accounting.utils.user.get_user_pk(username: str) int
Returns the primary key value of the user by the username.
- Parameters:
username – The username.
- Returns:
The primary key value of the user by the username.
- accounting.utils.user.has_user(username: str) bool
Returns whether a user by the username exists.
- Parameters:
username – The username.
- Returns:
True if the user by the username exists, or False otherwise.
- accounting.utils.user.init_user_utils(utils: UserUtilityInterface) None
Initializes the user utilities.
- Parameters:
utils – The user utilities.
- Returns:
None.
- accounting.utils.user.user_cls
The user class.
- accounting.utils.user.user_pk_column: Column = Column(None, Integer(), table=None)
The primary key column of the user class.
Module contents
The independent utilities.
This module should not import any other module from the application.