Skip to content

Models

components.payment_gateway.subcomponents.ledgers.models.helpers

load_all_models

load_all_models()
Source code in components/payment_gateway/subcomponents/ledgers/models/helpers.py
def load_all_models() -> list[type[DbModel]]:
    from components.payment_gateway.subcomponents.ledgers.models.ledger import (
        Ledger,
    )
    from components.payment_gateway.subcomponents.ledgers.models.ledger_entry import (
        LedgerEntry,
    )

    return [Ledger, LedgerEntry]

components.payment_gateway.subcomponents.ledgers.models.ledger

Ledger

Bases: BaseModel

__table_args__ class-attribute instance-attribute

__table_args__ = {'schema': PAYMENT_GATEWAY_SCHEMA_NAME}

__tablename__ class-attribute instance-attribute

__tablename__ = 'ledger'

additional_admin_properties class-attribute instance-attribute

additional_admin_properties = ['balance']

balance property

balance

description class-attribute instance-attribute

description = mapped_column(Text, nullable=False)

entries class-attribute instance-attribute

entries = relationship(
    "LedgerEntry",
    back_populates="ledger",
    order_by="LedgerEntry.created_at.desc()",
    uselist=True,
    viewonly=True,
)

is_terminated property

is_terminated

last_entry class-attribute instance-attribute

last_entry = relationship(
    "LedgerEntry",
    uselist=False,
    viewonly=True,
    primaryjoin="and_(   LedgerEntry.ledger_id == Ledger.id,   LedgerEntry.created_at == (       select(func.max(LedgerEntry.created_at))       .where(LedgerEntry.ledger_id == Ledger.id)       .correlate(Ledger)       .scalar_subquery()   ))",
)

reference class-attribute instance-attribute

reference = mapped_column(Text, nullable=True, index=True)

terminated_at class-attribute instance-attribute

terminated_at = mapped_column(DateTime, nullable=True)

Termination is done at the initiative of the business layer. Ledgers in terminal state cannot be modified or used anymore.

components.payment_gateway.subcomponents.ledgers.models.ledger_entry

LedgerEntry

Bases: BaseModel

__table_args__ class-attribute instance-attribute

__table_args__ = {'schema': PAYMENT_GATEWAY_SCHEMA_NAME}

__tablename__ class-attribute instance-attribute

__tablename__ = 'ledger_entry'

amount class-attribute instance-attribute

amount = mapped_column(Integer, nullable=False)

description class-attribute instance-attribute

description = mapped_column(Text, nullable=True)

ending_balance class-attribute instance-attribute

ending_balance = mapped_column(Integer, nullable=False)

entry_metadata class-attribute instance-attribute

entry_metadata = mapped_column(
    JSONB(none_as_null=True), nullable=True
)

Note: 'metadata' is reserved so use 'entry_metadata' instead.

external_transaction_id class-attribute instance-attribute

external_transaction_id = mapped_column(
    String(255), nullable=True, index=True
)

ID used to identify transactions originating from the external payment service provider.

ledger class-attribute instance-attribute

ledger = relationship(
    Ledger, foreign_keys=ledger_id, back_populates="entries"
)

ledger_id class-attribute instance-attribute

ledger_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey(id),
    index=True,
    nullable=True,
)

occurred_at class-attribute instance-attribute

occurred_at = mapped_column(DateTime, nullable=False)

opening_balance class-attribute instance-attribute

opening_balance = mapped_column(Integer, nullable=False)

reference class-attribute instance-attribute

reference = mapped_column(Text, nullable=True)