models.transaction

Represents a financial Transaction.

Module Contents

Classes

Transaction

Represents a Transaction in the sense of an original source document.

class models.transaction.Transaction

Bases: python_accounting.mixins.IsolatingMixin, python_accounting.models.Recyclable

Represents 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:
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