models
Provides models for accounting objects.
Submodules
Package Contents
Classes
The accounting model base class |
|
Interface for associating recycled objects with its models. |
|
Represents a Currency in terms of a label and an ISO Currency Code. |
|
Represents an authenticatable User with access to an Entity. |
|
Represents an accounting model that has been recycled. |
|
Represents a financial cycle for the Reporting Entity. |
|
Represents the Reporting Entity. |
|
Represents an account which groups related Transactions. |
|
Represents a grouping of Accounts of the same type. |
|
Represents the other side of the double entry from the main account of a Transaction. |
|
Represents a Transaction in the sense of an original source document. |
|
Represents a Balance brought down from previous Reporting Periods. |
|
Represents a Tax applied to a Transaction's Line Item. |
|
Represents an entry in the Ledger. (Should never have to be invoked directly). |
|
Represents an assigment of a clearable type to an assignable Transaction. |
- class models.Base
Bases:
sqlalchemy.orm.DeclarativeBaseThe accounting model base class
- id: sqlalchemy.orm.Mapped[int]
The primary key of the model database record.
- Type:
id (int)
- created_at: sqlalchemy.orm.Mapped[datetime.datetime]
The time the database record was created.
- Type:
created_at (datetime)
- updated_at: sqlalchemy.orm.Mapped[datetime.datetime]
The time the database record was last modified.
- Type:
update_at (datetime)
- __tablename__() str
- class models.Recyclable
Bases:
python_accounting.models.BaseInterface for associating recycled objects with its models.
- deleted_at: sqlalchemy.orm.Mapped[datetime.datetime]
The time the model was recycled.
- Type:
(datetime, optional)
- destroyed_at: sqlalchemy.orm.Mapped[datetime.datetime]
The time the model was recycled permanently deleted.
- Type:
(datetime, optional)
- recycled_type: sqlalchemy.orm.Mapped[str]
The class name of the recycled model.
- Type:
(str)
- history: sqlalchemy.orm.Mapped[List[Recycled]]
A list of deletions and restorations for the model.
- Type:
(list)
- __mapper_args__
- class models.Currency
Bases:
python_accounting.mixins.IsolatingMixin,python_accounting.models.RecyclableRepresents a Currency in terms of a label and an ISO Currency Code.
- __mapper_args__
- id: sqlalchemy.orm.Mapped[int]
The primary key of the Category database record.
- Type:
(int)
- name: sqlalchemy.orm.Mapped[str]
The label of the Currency.
- Type:
(str)
- code: sqlalchemy.orm.Mapped[str]
The ISO 4217 currency code symbol.
- Type:
(str)
- __repr__() str
- class models.User
Bases:
python_accounting.mixins.IsolatingMixin,models.base.BaseRepresents an authenticatable User with access to an Entity.
- name: sqlalchemy.orm.Mapped[str]
The name of the User.
- Type:
(str)
- email: sqlalchemy.orm.Mapped[str]
A unique email to identify the User.
- Type:
(str)
- __repr__() str
- class models.Recycled
Bases:
python_accounting.mixins.IsolatingMixin,models.base.BaseRepresents an accounting model that has been recycled.
- recycled_id: sqlalchemy.orm.Mapped[int]
The id of the model that has been recycled.
- Type:
(int)
- restored_at: sqlalchemy.orm.Mapped[datetime.datetime]
The time the model was restored.
- Type:
(datetime, optional)
- subject: sqlalchemy.orm.Mapped[Recyclable]
The model that was recycled/restored.
- Type:
- __repr__() str
- class models.ReportingPeriod
Bases:
python_accounting.mixins.IsolatingMixin,python_accounting.models.RecyclableRepresents a financial cycle for the Reporting Entity.
- class Status(*args, **kwds)
Bases:
enum.EnumRepresents a Reporting Period’s status.
- OPEN = 0
The period is current and Transactions may be posted to it.
- ADJUSTING = 1
The period is past and only Journal Entry Transactions may be posted to it (E.g Audit Adjustments).
- CLOSED = 2
The period is past and no more Transactions may be posted to it.
- __tablename__ = 'reporting_period'
- __table_args__ = ()
- __mapper_args__
- id: sqlalchemy.orm.Mapped[int]
The primary key of the Reporting Period database record.
- Type:
(int)
- calendar_year: sqlalchemy.orm.Mapped[int]
The calendar year associated with the ReportingPeriod.
- Type:
(int)
- period_count: sqlalchemy.orm.Mapped[int]
The number of periods since the system has been in use by the Entity.
- Type:
(int)
- status: sqlalchemy.orm.Mapped[ReportingPeriod.Status]
The status of the Reporting Period.
- Type:
- __repr__() str
- static date_year(date: datetime.datetime = None, entity=None) int
Returns the calendar year for the given date.
- Parameters:
date (datetime, optional) – The date whose calendar year is to be found. Defaults to the current date.
entity (int, optional) – The Entity for whom the calendar year is to be found. If absent, defaults to the calendar year.
- Returns:
The calendar year.
- Return type:
int
- static get_period(session, date: datetime.datetime) ReportingPeriod
Returns the reporting period for the given date.
- Parameters:
session (Session) – The accounting session to which the Reporting Period belongs.
date (datetime) – The date whose Reporting Period is to be found.
- Raises:
MissingReportingPeriodError – If there no Reporting Period exists for the given date.
- Returns:
The Reporting Period.
- Return type:
- validate(session) None
Validates the Reporting Period properties.
- Parameters:
session (Session) – The accounting session to which the ReportingPeriod belongs.
- Raises:
DuplicateReportingPeriodError – If there already exists a Reporting Period for the same calendar year.
MultipleOpenPeriodsError – If there already exists a Reporting Period in the OPEN status.
- Returns:
None
- interval(date: datetime.datetime = None) dict
Returns the start and end dates of the Reporting Period.
- Parameters:
session (Session) – The accounting session to which the Reporting Period belongs.
date (datetime) – The date for whose Reporting Period’s interval is to be found.
- Raises:
MissingReportingPeriodError – If there no Reporting Period exists for the given date.
- Returns:
The Reporting Period.
- Return type:
- class models.Entity
Bases:
python_accounting.models.RecyclableRepresents the Reporting Entity.
- __mapper_args__
- id: sqlalchemy.orm.Mapped[int]
The primary key of the Entity database record.
- Type:
(int)
- name: sqlalchemy.orm.Mapped[str]
The Name of the Entity.
- Type:
(str)
- multi_currency: sqlalchemy.orm.Mapped[bool]
Determines if the Entity can have Transactions in currencies other than its base Currency. Defaults to False.
- Type:
(bool, optional)
- mid_year_balances: sqlalchemy.orm.Mapped[bool]
Determines if the Entity can have Opening Balances withing the current Reporting Period. Defaults to False.
- Type:
(bool, optional)
- year_start: sqlalchemy.orm.Mapped[int]
The month at which the Entity’s Reporting Periods begin, expressed as a number between 1 and 12. Defaults to 1 (January).
- Type:
(int, optional)
- locale: sqlalchemy.orm.Mapped[str]
The language format to be used to represent amounts. Defaults to en_GB.
- Type:
(str)
- currency_id: sqlalchemy.orm.Mapped[int]
The id of the Reporting Currency of the Entity.
- Type:
(int, optional)
- reporting_period_id: sqlalchemy.orm.Mapped[int]
The id of the current Reporting Period of the Entity.
- Type:
(int, optional)
- reporting_period: sqlalchemy.orm.Mapped[python_accounting.models.ReportingPeriod]
The current Reporting Period of the Entity.
- Type:
- users: sqlalchemy.orm.Mapped[List[User]]
A list of Users that belong to the Entity.
- Type:
(list of User)
- __repr__() str
- class models.Account
Bases:
python_accounting.mixins.IsolatingMixin,python_accounting.models.recyclable.RecyclableRepresents an account which groups related Transactions.
- AccountType
Account Types as defined by IFRS and GAAP.
- Type:
(StrEnum)
- purchasables
A list of Account Types that can be used in purchasing Transactions.
- Type:
(list of Account.AccountType)
- __mapper_args__
- id: sqlalchemy.orm.Mapped[int]
The primary key of the Account database record.
- Type:
(int)
- name: sqlalchemy.orm.Mapped[str]
The label of the Account.
- Type:
(str)
- description: sqlalchemy.orm.Mapped[str]
A narration of the purpose of the Account.
- Type:
(str, optional)
- account_code: sqlalchemy.orm.Mapped[int]
A serially generated code based on the type of the Account.
- Type:
(int)
- account_type: sqlalchemy.orm.Mapped[strenum.StrEnum]
The type of the Account.
- Type:
(AccountType)
- currency_id: sqlalchemy.orm.Mapped[int]
The id of the Currency model associated with the Account.
- Type:
(int)
- category_id: sqlalchemy.orm.Mapped[int]
The id of the Category model to which the Account belongs.
- Type:
(int, optional)
- currency: sqlalchemy.orm.Mapped[Currency]
The Currency associated with the Account.
- Type:
(Currency)
- category: sqlalchemy.orm.Mapped[Category]
The Category to which the Account belongs.
- Type:
(Category, optional)
- _get_account_code(session) int
- __repr__() str
- balance_movement(session, start_date: datetime.datetime, end_date: datetime.datetime) decimal.Decimal
Get the change in the account balance between the given dates.
- Parameters:
session (Session) – The accounting session to which the Account belongs.
start_date (datetime) – The earliest transaction date for Transaction amounts to be included in the balance.
end_date (datetime) – The latest transaction date for Transaction amounts to be included in the balance.
- Returns:
The difference between the balance of the Account at the start date and end date.
- Return type:
Decimal
- static section_balances(session, account_types: list, start_date: datetime.datetime = None, end_date: datetime.datetime = None, full_balance: bool = True) dict
Gets the opening, movement and closing balances of the accounts of the given section (account types), organized by category.
- Parameters:
session (Session) – The accounting session to which the Account belongs.
account_types (list of Account.AccountType) – The Account types belonging to the section.
start_date (datetime) – The earliest transaction date for Transaction amounts to be included in the balance.
end_date (datetime) – The latest transaction date for Transaction amounts to be included in the balance.
full_balance (bool) – Whether to include opening balance amounts in the balance.
- Returns:
A summary of the total opening, balance movement and closing balance, which details of totals by Category and the Accounts contained in each Category.
opening (Decimal): The sum of opening balances of Accounts in the section.
movement (Decimal): The movememt of the balances of Accounts in the section.
closing (Decimal): The sum of opening closing of Accounts in the section.
categories (dict): The Accounts belonging to the section separated by Category.
- Return type:
dict
- opening_balance(session, year: int = None) decimal.Decimal
Gets the the opening balance for the account for the given year.
- Parameters:
session (Session) – The accounting session to which the Account belongs.
year (int) – The calendar year for which to retrieve the opening balance.
- Returns:
The total opening balance of the Account for the year.
- Return type:
Decimal
- closing_balance(session, end_date: datetime.datetime = None) decimal.Decimal
Gets the the closing balance of the Account as at the given date.
- Parameters:
session (Session) – The accounting session to which the Account belongs.
end_date (datetime) – The latest transaction date for Transaction amounts to be included in the balance.
- Returns:
The total opening balance of the Account for the year.
- Return type:
Decimal
- statement(session, start_date: datetime.datetime = None, end_date: datetime.datetime = None, schedule: bool = False) dict
- Gets a chronological listing of the Transactions posted to the Account between
the dates given.
- Parameters:
session (Session) – The accounting session to which the Account belongs.
start_date (datetime) – The earliest transaction date for Transaction amounts to be included in the statement.
end_date (datetime) – The latest transaction date for Transaction amounts to be included in the statement.
schedule (bool) – Whether to exclude assignable Transactions and only list clearable Transactions with outstanding amounts.
- Raises:
InvalidAccountTypeError – If the Account type is not Receivable or Payable.
- Returns:
With a A summary of the opening and closing balance in the case of a statement, the total, cleared and uncleared amounts if its a schedule together with a list of Transactions.
- Statements.
opening_balance (Decimal): The balance of the Account at the beginning of the statement period.
transactions (list): Transactions posted to the Account during the period.
closing_balance (Decimal): The balance of the Account at the end of the statement period.
- Schedule.
transactions (list): Outstanding clearable Transactions posted to the Account as at the end date.
total_amount (Decimal): The total amount of the Transactions in the Schdeule.
cleared_amount (Decimal): The amount of the Transactions in the Schdeule that has been cleared.
uncleared_amount (Decimal): The amount of the Transactions in the Schdeule that is still outstanding.
- Return type:
dict
- validate(session) None
Validates the Account properties.
- Parameters:
session (Session) – The accounting session to which the Account belongs.
- Raises:
InvalidCategoryAccountTypeError – If the account type of the Account does not match that of its assigned Category.
- Returns:
None
- validate_delete(session) None
Validates if the account can be deleted.
- Parameters:
session (Session) – The accounting session to which the Account belongs.
- Raises:
HangingTransactionsError – If the Account has had Transactions during the current Reporting period.
- Returns:
None
- class models.Category
Bases:
python_accounting.mixins.IsolatingMixin,python_accounting.models.RecyclableRepresents a grouping of Accounts of the same type.
- __mapper_args__
- id: sqlalchemy.orm.Mapped[int]
The primary key of the Category database record.
- Type:
(int)
- name: sqlalchemy.orm.Mapped[str]
The label of the Category.
- Type:
(str)
- category_account_type: sqlalchemy.orm.Mapped[strenum.StrEnum]
The Account type of the members of the Category.
- Type:
(list of Account.AccountType)
- accounts: sqlalchemy.orm.Mapped[List[python_accounting.models.Account]]
Accounts that belong to the Category.
- Type:
(list)
- __repr__() str
- validate(_) None
Validates the Category properties.
- Parameters:
session (Session) – The accounting session to which the Category belongs.
- Raises:
InvalidAccountTypeError – If the category account type is not one of Account.AccountType.
- Returns:
None
- account_balances(session, end_date: datetime.datetime = None) dict
Returns the Accounts belonging to the Category and their balances.
- Parameters:
session (Session) – The accounting session to which the Account belongs.
end_date (datetime) – The latest transaction date for Transaction amounts to be included in the Account balances.
- Returns:
With a A summary of the total of the Account balances of the together with a list of the Accounts themselves.
total (Decimal): The total of the closing balances of the Category accounts as at the end date.
accounts (list): The Accounts belonging to the Category.
- Return type:
dict
- class models.LineItem(**kw: Any)
Bases:
python_accounting.mixins.IsolatingMixin,python_accounting.models.RecyclableRepresents the other side of the double entry from the main account of a Transaction.
- __tablename__ = 'line_item'
- __mapper_args__
- id: sqlalchemy.orm.Mapped[int]
The primary key of the Line Item database record.
- Type:
(int)
- narration: sqlalchemy.orm.Mapped[str]
A short description of the Line Item’s contribution to the Transaction.
- Type:
(str)
- quantity: sqlalchemy.orm.Mapped[decimal.Decimal]
The multiple of the Line Item amount to be posted to the Ledger.
- Type:
(Decimal)
- amount: sqlalchemy.orm.Mapped[decimal.Decimal]
The amount to be posted to the Line Item Account.
- Type:
(Decimal)
- credited: sqlalchemy.orm.Mapped[bool]
Determines whether the Line Item amount will be posted to the credit side of the Line Item Account. Defaults to False.
- Type:
(bool, optional)
- tax_inclusive: sqlalchemy.orm.Mapped[bool]
Determines whether the Tax amount of the Line Item is included in the Line Item amount. Defaults to False.
- Type:
(bool, optional)
- account_id: sqlalchemy.orm.Mapped[int]
The id of the Account model associated with the Line Item.
- Type:
(int)
- transaction_id: sqlalchemy.orm.Mapped[int]
The id of the Transaction model associated with the Line Item.
- Type:
(int, optional)
- tax_id: sqlalchemy.orm.Mapped[int]
The id of the Tax model associated with the Line Item.
- Type:
(int, optional)
- account: sqlalchemy.orm.Mapped[Account]
The the Account model associated with the Line Item.
- Type:
(Account)
- transaction: sqlalchemy.orm.Mapped[Transaction]
The Transaction model associated with the Line Item.
- Type:
(Transaction, optional)
- ledgers: sqlalchemy.orm.Mapped[List[Ledger]]
The Ledger models associated with the Line Item.
- Type:
(list)
- validate_ledgers(key, ledger, is_remove)
Validates adding or removing of Line Item Ledgers.
- Raises:
ValueError – If the Line Item Ledgers are manually added or removed.
- __repr__() str
- validate(_) None
Validates the Line Item properties.
- Parameters:
session (Session) – The accounting session to which the Line Item belongs.
- Raises:
NegativeValueError – If the Line Item amount or quantity is less than 0.
- Returns:
None
- validate_delete(session) None
Validates if the line item can be deleted.
- class models.Transaction
Bases:
python_accounting.mixins.IsolatingMixin,python_accounting.models.RecyclableRepresents a Transaction in the sense of an original source document.
- property tax: dict
The taxes that have been applied to the transaction. - taxes (dict): The taxes applied to the Transaction and their amounts. - amount (str): The total tax applied to the Transaction.
- property is_posted: bool
Check if the Transaction has been posted to the ledger
- property amount: decimal.Decimal
The amount of the Transaction.
- TransactionType
Transaction Types representing standard source document Transactions.
- Type:
(StrEnum)
- __table_args__ = ()
- __tablename__ = 'transaction'
- __mapper_args__
- id: sqlalchemy.orm.Mapped[int]
The primary key of the Transaction database record.
- Type:
(int)
- transaction_date: sqlalchemy.orm.Mapped[datetime.datetime]
The date of the Transaction.
- Type:
(datetime)
- transaction_no: sqlalchemy.orm.Mapped[str]
Serially generated indentifier for the Transaction
- Type:
(str)
- transaction_type: sqlalchemy.orm.Mapped[strenum.StrEnum]
The Transaction type of the Transaction.
- Type:
(TransactionType)
- narration: sqlalchemy.orm.Mapped[str]
A short description of the purpose of the Transaction.
- Type:
(str)
- reference: sqlalchemy.orm.Mapped[str]
Identifying information about the Transaction.
- Type:
(str, optional)
- main_account_amount: sqlalchemy.orm.Mapped[decimal.Decimal]
The amount to be posted to the Transaction main Account. Only applies to compound (Journal Entry) Transactions.
- Type:
(Decimal, optional)
- credited: sqlalchemy.orm.Mapped[bool]
Determines whether the Transaction amount will be posted to the credit side of the main Account. Defaults to True.
- Type:
(bool, optional)
- compound: sqlalchemy.orm.Mapped[bool]
Determines whether the (Journal Entry) Transaction amount can have Line Items on both sides of the double entry.
- Type:
(bool, optional)
- currency_id: sqlalchemy.orm.Mapped[int]
The id of the Currency associated with the Transaction.
- Type:
(int)
- account_id: sqlalchemy.orm.Mapped[int]
The id of the Account model to which Transaction amounts are to be posted.
- Type:
(int)
- currency: sqlalchemy.orm.Mapped[Currency]
The Currency associated with the Transaction.
- Type:
(Currency)
- account: sqlalchemy.orm.Mapped[python_accounting.models.Account]
The Account model to which Transaction amounts are to be posted.
- Type:
(Account)
- line_items: sqlalchemy.orm.Mapped[Set[python_accounting.models.LineItem]]
The Line Items models associated with the Transaction.
- Type:
(Set)
- ledgers: sqlalchemy.orm.Mapped[List[Ledger]]
The Ledger models associated with the Transaction.
- Type:
(list)
- validate_line_items(_, line_item, is_remove)
Validates adding or removing of Transaction Line Items.
- Raises:
PostedTransactionError – If the Transaction is posted and Line Items are added or removed from it.
ValueError – If the unsaved Line Item are added or removed from the Transaction.
- validate_ledgers(key, ledger, is_remove)
Validates adding or removing of Transaction Ledgers
- Raises:
ValueError – If the Transaction Ledgers are manually added or removed.
- __repr__() str
- _get_main_account(session) python_accounting.models.Account
- _transaction_no(session, transaction_type, reporting_period) str
- is_secure(session) bool
Verify that the Transaction’s Ledgers have not been tampered with.
- post(session) None
Posts the Transaction to the Ledger.
- Parameters:
session (Session) – The accounting session to which the Reporting Period belongs.
- Raises:
MissingLineItemError – If the Transaction has no Line Items.
- Returns:
None
- contribution(session, account: python_accounting.models.Account) decimal.Decimal
Gets the amount contributed by the account to the transaction total.
- Parameters:
session (Session) – The accounting session to which the Reporting Period belongs.
account (Account) – The Account who’s contribution is to be found.
- Returns:
The amount posted to the Account by the Transaction.
- Return type:
Decimal
- validate(session) None
Validates the Transaction properties.
- Parameters:
session (Session) – The accounting session to which the Balance belongs.
- Raises:
PostedTransactionError – If Transaction is already posted.
ClosedReportingPeriodError – If the Transaction date is with a Reporting Period in the CLOSED status.
AdjustingReportingPeriodError – If the Transaction date is with a Reporting Period in the ADJUSTING status and is not a Journal Entry.
InvalidTransactionDateError – If the Transaction date is exactly the beginning of the Reporting Period.
InvalidTransactionTypeError – If the Transaction type is being modified.
RedundantTransactionError – If the Transaction main Account is also one of its Line Items Accounts.
- Returns:
None
- validate_delete(_) None
Validates if the Transaction can be deleted.
- Parameters:
session (Session) – The accounting session to which the Balance belongs.
- Raises:
PostedTransactionError – If Transaction is already posted.
- Returns:
None
- class models.Balance
Bases:
python_accounting.mixins.IsolatingMixin,python_accounting.mixins.ClearingMixin,python_accounting.models.RecyclableRepresents a Balance brought down from previous Reporting Periods.
- property is_posted: bool
is_posted analog for the assignment model.
- property credited: bool
credited analog for the assignment model.
- property compound: bool
compound analog for the assignment model.
- BalanceType
The double entry types of Balances.
- Type:
(StrEnum)
- BalanceTransactions
A list of Transaction Types that can have Balances.
- Type:
(StrEnum)
- __mapper_args__
- id: sqlalchemy.orm.Mapped[int]
The primary key of the Account database record.
- Type:
(int)
- transaction_date: sqlalchemy.orm.Mapped[datetime.datetime]
The date of the Balance Transaction.
- Type:
(datetime)
- reference: sqlalchemy.orm.Mapped[str]
Identifying information about the Balance Transaction.
- Type:
(str, optional)
- transaction_no: sqlalchemy.orm.Mapped[str]
The Transaction number of the Balance Transaction.
- Type:
(str)
- transaction_type: sqlalchemy.orm.Mapped[strenum.StrEnum]
The Transaction type of the Balance Transaction.
- Type:
(TransactionType)
- amount: sqlalchemy.orm.Mapped[decimal.Decimal]
The amount outstanding on the Balance Transaction.
- Type:
(Decimal)
- balance_type: sqlalchemy.orm.Mapped[strenum.StrEnum]
The side of the double entry to post the Balance amount.
- Type:
(BalanceType)
- currency_id: sqlalchemy.orm.Mapped[int]
The id of the Currency model associated with the Balance.
- Type:
(int)
- account_id: sqlalchemy.orm.Mapped[int]
The id of the Account model to which the Balance belongs.
- Type:
(int)
- reporting_period_id: sqlalchemy.orm.Mapped[int]
The id of the Reporting Period model to which the Balance belongs.
- Type:
(int)
- currency: sqlalchemy.orm.Mapped[python_accounting.models.Currency]
The Currency model associated with the Balance.
- Type:
(Currency)
- account: sqlalchemy.orm.Mapped[python_accounting.models.Account]
The Account model to which the Balance belongs.
- Type:
(Account)
- reporting_period: sqlalchemy.orm.Mapped[python_accounting.models.ReportingPeriod]
The Reporting Period model to which the Balance belongs.
- Type:
- __repr__() str
- static opening_trial_balance(session, year: int = None) dict
Gets the total opening balances for the Entity’s accounts for the given year.
- Parameters:
session (Session) – The accounting session to which the Account belongs.
year (int, optional) – The calendar year to retrieve the opening trial balance for. Defaults to the Balance’s Entity current Reporting Period’s calendar year.
- Returns:
With a A summary of the debit and credit balances of the Accounts together with a list of the Accounts themselves.
debits (Decimal): The total debit balance.
credits (Decimal): The total credit balance.
accounts (Decimal): Accounts constituting the opening trial balance.
- Return type:
dict
- validate(session) None
Validates the Balance properties.
- Parameters:
session (Session) – The accounting session to which the Balance belongs.
- Raises:
NegativeValueError – If the Balance amount is less than 0.
InvalidBalanceAccountError – If the Balance main Account is an Income Statement Account.
InvalidBalanceTransactionError – If the Balance Transaction type is not one of the Balance Transaction types.
InvalidBalanceDateError – If the Balance Transaction date is within the current reporting period and the Entity does not allow mid year balances.
- Returns:
None
- class models.Tax
Bases:
python_accounting.mixins.IsolatingMixin,python_accounting.models.RecyclableRepresents a Tax applied to a Transaction’s Line Item.
- __mapper_args__
- id: sqlalchemy.orm.Mapped[int]
The primary key of the Tax database record.
- Type:
(int)
- name: sqlalchemy.orm.Mapped[str]
The label of the Tax.
- Type:
(str)
- code: sqlalchemy.orm.Mapped[str]
A shorthand representation of the Tax.
- Type:
(str)
- rate: sqlalchemy.orm.Mapped[decimal.Decimal]
The percentage rate of the Tax.
- Type:
(Decimal)
- account_id: sqlalchemy.orm.Mapped[int]
The id of the Account model to which Tax amounts are posted.
- Type:
(int)
- account: sqlalchemy.orm.Mapped[python_accounting.models.Account]
The Account model to which Tax amounts are posted.
- Type:
(Account)
- __repr__() str
- validate(session) None
Validates the Tax properties.
- Parameters:
session (Session) – The accounting session to which the Balance belongs.
- Raises:
NegativeValueError – If the Tax rate is less than 0.
MissingTaxAccountError – If the Tax rate is greater than 0 and the Tax Account is not set.
InvalidTaxAccountError – If the Tax Account type is not Control.
- Returns:
None
- validate_delete(session) None
Validates if the Tax can be deleted.
- Parameters:
session (Session) – The accounting session to which the Tax belongs.
- Raises:
HangingTransactionsError – If there exists posted Transactions with Line Items that have this Tax applied to them.
- Returns:
None
- class models.Ledger
Bases:
python_accounting.mixins.IsolatingMixin,python_accounting.models.RecyclableRepresents an entry in the Ledger. (Should never have to be invoked directly).
- __mapper_args__
- id: sqlalchemy.orm.Mapped[int]
The primary key of the ledger database record.
- Type:
(int)
- transaction_date: sqlalchemy.orm.Mapped[datetime.datetime]
The date of the Transaction associated with the Ledger.
- Type:
(datetime)
- entry_type: sqlalchemy.orm.Mapped[strenum.StrEnum]
The side of the double entry to which the Ledger is posted.
- Type:
(BalanceType)
- amount: sqlalchemy.orm.Mapped[decimal.Decimal]
The amount posted to the Ledger by the entry.
- Type:
(Decimal)
- hash: sqlalchemy.orm.Mapped[str]
The encoded contents of the Ledger entry.
- Type:
(str)
- transaction_id: sqlalchemy.orm.Mapped[int]
The id of the Transaction associated with the Ledger.
- Type:
(int)
- currency_id: sqlalchemy.orm.Mapped[int]
The id of the Currency associated with the Ledger.
- Type:
(int)
- post_account_id: sqlalchemy.orm.Mapped[int]
The id of the Account to which the Ledger is posted.
- Type:
(int)
- folio_account_id: sqlalchemy.orm.Mapped[int]
The id of the Account to which the opposite side of Ledger is posted.
- Type:
(int)
- line_item_id: sqlalchemy.orm.Mapped[int]
The id of the Line Item associated with the Ledger.
- Type:
(int, optional)
- tax_id: sqlalchemy.orm.Mapped[int]
The id of the Tax associated with the Ledger.
- Type:
(int, optional)
- transaction: sqlalchemy.orm.Mapped[python_accounting.models.Transaction]
The Transaction associated with the Ledger.
- Type:
- currency: sqlalchemy.orm.Mapped[Currency]
The Currency associated with the Ledger.
- Type:
(Currency)
- post_account: sqlalchemy.orm.Mapped[Account]
The main Account associated with the Ledger.
- Type:
(Account)
- folio_account: sqlalchemy.orm.Mapped[Account]
The oppeite double entry Account associated with the Ledger.
- Type:
(Account)
- line_item: sqlalchemy.orm.Mapped[LineItem]
The LineItem associated with the Ledger.
- Type:
(LineItem)
- __repr__() str
- static _allocate_amount(session, post, amount, posts, folios, transaction, entry_type) None
- static _make_compound_ledgers(session, posts: list, folios: list, transaction: python_accounting.models.Transaction, entry_type: python_accounting.models.Balance.BalanceType) None
- static _post_compound(session, transaction: python_accounting.models.Transaction) None
- static _transaction_ledgers(transaction: python_accounting.models.Transaction) tuple
- static _post_simple(session, transaction: python_accounting.models.Transaction) None
- static post(session, transaction: python_accounting.models.Transaction) None
Posts the Transaction to the ledger.
- Parameters:
session (Session) – The accounting session to which the Account belongs.
transaction (Transaction) – The Transaction to be posted.
- get_hash(connection) None
Calculate the hash of the Ledger.
- Parameters:
connection (Connection) – The database connection of the accounting session
belongs. (to which the Ledger) –
- Returns:
None
- class models.Assignment
Bases:
python_accounting.mixins.IsolatingMixin,python_accounting.models.BaseRepresents an assigment of a clearable type to an assignable Transaction.
- clearables
A list of Transaction Types that can be cleared by assignable Transactions.
- Type:
(list of Transaction.TransactionType)
- assignables
A list of Transaction Types that can have cleareable Transactions assigned to them.
- Type:
(list of Transaction.TransactionType)
- assignment_date: sqlalchemy.orm.Mapped[datetime.datetime]
The date of the Assignment.
- Type:
(datetime)
- transaction_id: sqlalchemy.orm.Mapped[int]
The id of the assignable Transaction in the Assignment.
- Type:
(int)
- assigned_id: sqlalchemy.orm.Mapped[int]
The id of the clearable Transaction|Balance in the Assignment.
- Type:
(int)
- assigned_type: sqlalchemy.orm.Mapped[str]
The class name of the clearable Transaction|Balance in the Assignment.
- Type:
(str)
- assigned_no: sqlalchemy.orm.Mapped[str]
The Transaction number of the clearable Transaction|Balance in the Assignment.
- Type:
(str)
- amount: sqlalchemy.orm.Mapped[decimal.Decimal]
The amount of the Assignment.
- Type:
(Decimal)
- transaction: sqlalchemy.orm.Mapped[python_accounting.models.Transaction]
The assignable Transaction in the Assignment.
- Type:
- __repr__() str
- assigned(session) python_accounting.models.Transaction
Get the clearable Transaction|Balance assigned to this assigment’s transaction.
- Parameters:
session (Session) – The accounting session to which the Assignment belongs.
- Returns:
The model cleared by this assignment.
- Return type:
- validate(session) None
Validates the Assignment properties.
- Parameters:
session (Session) – The accounting session to which the Assignment belongs.
- Raises:
ValueError – If the assignable Transaction or clearable Transaction|Balance could not be found.
UnassignableTransactionError – If the assignable Transaction type is not one of the assignable types.
UnclearableTransactionError – If the clearable Transaction type is not one of the clearable types.
UnpostedAssignmentError – If either the assignable or clearable Transaction is not posted.
InsufficientBalanceError – If the remaining balance in the assignable Transaction is less than the Assignment amount.
OverclearanceError – If the Assignment amount is greater than the clearable Transaction|Balance uncleared amount.
CompoundTransactionAssignmentError – If either the assignable or clearable Journal Entry is a compound Transaction.
SelfClearanceError – If the assignable and clearable Transaction of the Assignment is the same.
InvalidAssignmentAccountError – If the assignable Transaction and clearable Transaction|Balance main Accounts are not the same.
MixedAssignmentError – If either an already Transaction is being cleared or an already cleared Transaction is being assigned.
- Returns:
None