Skip to content

Models

components.es.subcomponents.billing.internal.models.brokers

invoice

EsInvoiceModelBroker

Bases: BaseModelBroker

create_invoice classmethod
create_invoice(
    invoice_number,
    event_date,
    issued_date,
    contract_ref,
    contract_type,
    month_amount,
    amount_to_charge,
    regularization_amount=0,
    previous_balance=None,
    payment_pending=False,
)
Source code in components/es/subcomponents/billing/internal/models/brokers/invoice.py
@classmethod
def create_invoice(
    cls,
    invoice_number: str,
    event_date: Month,
    issued_date: date,
    contract_ref: str,
    contract_type: ContractType,
    month_amount: int,
    amount_to_charge: int,
    regularization_amount: int = 0,
    previous_balance: int | None = None,
    payment_pending: bool = False,
) -> EsInvoice:
    invoice = cls.model(
        invoice_number=invoice_number,
        event_date=event_date,
        issued_date=issued_date,
        due_date=Month.current().last_day,
        contract_ref=contract_ref,
        contract_type=contract_type,
        month_amount=month_amount,
        amount_to_charge=amount_to_charge,
        regularization_amount=regularization_amount,
        remaining_balance=month_amount + regularization_amount,
        previous_balance=previous_balance,
        payment_pending=payment_pending,
        billing_reason=BillingReason.regular,
    )

    current_session.add(invoice)
    current_session.flush()

    return invoice
get_invoice classmethod
get_invoice(id, with_premium_entries=False)
Source code in components/es/subcomponents/billing/internal/models/brokers/invoice.py
@classmethod
def get_invoice(cls, id: UUID, with_premium_entries: bool = False) -> EsInvoice:
    try:
        autoload = {} | cls.autoload
        if with_premium_entries:
            autoload |= {
                "premium_entries": {
                    "enrollment": {"policy": True},
                    "enrollment_option": True,
                }
            }
        return cls.query(custom_autoload=autoload).filter(cls.model.id == id).one()  # type: ignore[no-any-return]
    except NoResultFound:
        raise BaseErrorCode.missing_resource(
            message=f"{cls.model.__name__} with id '{id}' not found"
        )
get_invoice_by_number classmethod
get_invoice_by_number(invoice_number)
Source code in components/es/subcomponents/billing/internal/models/brokers/invoice.py
@classmethod
def get_invoice_by_number(cls, invoice_number: str) -> EsInvoice | None:
    return (
        cls.query().filter(cls.model.invoice_number == invoice_number).one_or_none()
    )
get_invoice_count_for_contract_and_month classmethod
get_invoice_count_for_contract_and_month(
    contract_identifier, month
)
Source code in components/es/subcomponents/billing/internal/models/brokers/invoice.py
@classmethod
def get_invoice_count_for_contract_and_month(
    cls, contract_identifier: ContractIdentifier, month: Month
) -> int:
    return (
        cls.query()
        .where(
            cls.model.contract_identifier == contract_identifier,
            cls.model.event_date == month.first_day,
        )
        .count()
    )
get_invoice_count_for_year classmethod
get_invoice_count_for_year(year)
Source code in components/es/subcomponents/billing/internal/models/brokers/invoice.py
@classmethod
def get_invoice_count_for_year(cls, year: int) -> int:
    return cls.query().filter(extract("year", cls.model.event_date) == year).count()
get_invoice_ids_for_contract_type_and_month classmethod
get_invoice_ids_for_contract_type_and_month(
    contract_type, month
)
Source code in components/es/subcomponents/billing/internal/models/brokers/invoice.py
@classmethod
def get_invoice_ids_for_contract_type_and_month(
    cls, contract_type: ContractType, month: Month
) -> list[UUID]:
    query = (
        cls.query()
        .where(
            cls.model.contract_type == contract_type,
            cls.model.event_date == month,
        )
        .order_by(cls.model.created_at.desc())
        .options(load_only(cls.model.id))
    )
    return [invoice.id for invoice in query.all()]
get_invoices_by_ids classmethod
get_invoices_by_ids(ids)
Source code in components/es/subcomponents/billing/internal/models/brokers/invoice.py
@classmethod
def get_invoices_by_ids(cls, ids: Iterable[UUID]) -> list[EsInvoice]:
    return (
        cls.query()
        .where(cls.model.id.in_(ids))
        .order_by(cls.model.created_at.desc())
        .all()
    )
get_invoices_for_contract_and_month classmethod
get_invoices_for_contract_and_month(
    contract_identifier, month
)
Source code in components/es/subcomponents/billing/internal/models/brokers/invoice.py
@classmethod
def get_invoices_for_contract_and_month(
    cls, contract_identifier: ContractIdentifier, month: Month
) -> list[EsInvoice]:
    return (
        cls.query()
        .where(
            cls.model.contract_identifier == contract_identifier,
            cls.model.event_date == month.first_day,
        )
        .order_by(cls.model.created_at.desc())
        .all()
    )
model class-attribute instance-attribute
model = EsInvoice

components.es.subcomponents.billing.internal.models.es_billing_task_execution

EsBillingTaskExecution

Bases: BaseBillingTaskExecution

__table_args__ class-attribute instance-attribute

__table_args__ = ({'schema': ES_SCHEMA},)

components.es.subcomponents.billing.internal.models.es_billing_task_execution_rq_job

EsBillingTaskExecutionRqJob

Bases: BaseBillingTaskExecutionRqJob[EsBillingTaskExecution]

__table_args__ class-attribute instance-attribute

__table_args__ = ({'schema': ES_SCHEMA},)

components.es.subcomponents.billing.internal.models.es_installment

EsInstallment

Bases: CoreInstallment

__table_args__ class-attribute instance-attribute

__table_args__ = ({'schema': ES_SCHEMA},)

installment_plan class-attribute instance-attribute

installment_plan = relationship(
    "EsInstallmentPlan",
    backref=backref(
        "installments",
        uselist=True,
        order_by="EsInstallment.created_at.asc()",
    ),
)

installment_plan_id

installment_plan_id()
Source code in components/es/subcomponents/billing/internal/models/es_installment.py
@declared_attr
def installment_plan_id(cls) -> Mapped[uuid.UUID]:
    return mapped_column(
        PostgreSQLUUID(as_uuid=True),
        ForeignKey("es.installment_plan.id"),  # noqa: ALN021
        nullable=False,
        index=True,
    )

is_controlled_debt property

is_controlled_debt

payments class-attribute instance-attribute

payments = relationship(
    "EsPayment",
    back_populates="installment",
    uselist=True,
    order_by="EsPayment.created_at.asc()",
)

components.es.subcomponents.billing.internal.models.es_installment_plan

EsInstallmentPlan

Bases: CoreInstallmentPlan

__table_args__ class-attribute instance-attribute

__table_args__ = ({'schema': ES_SCHEMA},)

components.es.subcomponents.billing.internal.models.es_invoice

EsInvoice

Bases: CoreInvoice

__allow_unmapped__ class-attribute instance-attribute

__allow_unmapped__ = True

__table_args__

__table_args__()
Source code in components/es/subcomponents/billing/internal/models/es_invoice.py
@declared_attr
def __table_args__(cls):  # type: ignore[no-untyped-def]
    return CoreInvoice.__table_args__ + ({"schema": ES_SCHEMA},)

appendix_file class-attribute instance-attribute

appendix_file = None

appendix_filename property

appendix_filename

appendix_uri class-attribute instance-attribute

appendix_uri = mapped_column(String(MAX_URI_SIZE))

country property

country

edit_model_permitted_for class-attribute instance-attribute

edit_model_permitted_for = {
    edit_in_flask_admin,
    edit_billing_tables,
}

filename property

filename

invoicee_name property

invoicee_name

payments class-attribute instance-attribute

payments = relationship(
    "EsPayment",
    back_populates="invoice",
    uselist=True,
    order_by="EsPayment.created_at.asc()",
)

premium_entries class-attribute instance-attribute

premium_entries = relationship(
    "EsPremiumEntry",
    back_populates="invoice",
    uselist=True,
    order_by="EsPremiumEntry.created_at.asc()",
)

remote_directory property

remote_directory

components.es.subcomponents.billing.internal.models.es_payment

EsPayment

Bases: CorePayment

__table_args__ class-attribute instance-attribute

__table_args__ = ({'schema': ES_SCHEMA},)

dispute_payment class-attribute instance-attribute

dispute_payment = relationship(
    "EsPayment",
    back_populates="disputed_payment",
    foreign_keys="EsPayment.disputed_payment_id",
    uselist=False,
)

disputed_payment class-attribute instance-attribute

disputed_payment = relationship(
    "EsPayment",
    foreign_keys="EsPayment.disputed_payment_id",
    uselist=False,
    remote_side="EsPayment.id",
    back_populates="dispute_payment",
)

disputed_payment_id class-attribute instance-attribute

disputed_payment_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey("es.payment.id"),
    nullable=True,
    unique=True,
    index=True,
)

edit_model_permitted_for class-attribute instance-attribute

edit_model_permitted_for = {
    edit_in_flask_admin,
    edit_billing_tables,
}

iban class-attribute instance-attribute

iban = relationship('EsIBAN', back_populates='payments')

iban_id class-attribute instance-attribute

iban_id = mapped_column(
    UUID(as_uuid=True), ForeignKey("es.iban.id"), index=True
)

installment class-attribute instance-attribute

installment = relationship(
    "EsInstallment", back_populates="payments"
)

installment_id class-attribute instance-attribute

installment_id = mapped_column(
    UUID(as_uuid=True), ForeignKey(id), index=True
)

invoice class-attribute instance-attribute

invoice = relationship(
    "EsInvoice", back_populates="payments"
)

invoice_id class-attribute instance-attribute

invoice_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey("es.invoice.id"),
    index=True,
)

refund_payments class-attribute instance-attribute

refund_payments = relationship(
    "EsPayment",
    back_populates="refunded_payment",
    uselist=True,
    order_by="EsPayment.created_at.asc()",
    foreign_keys="EsPayment.refunded_payment_id",
)

refunded_payment class-attribute instance-attribute

refunded_payment = relationship(
    "EsPayment",
    foreign_keys="EsPayment.refunded_payment_id",
    uselist=False,
    remote_side="EsPayment.id",
    back_populates="refund_payments",
)

refunded_payment_id class-attribute instance-attribute

refunded_payment_id = mapped_column(
    UUID(as_uuid=True),
    ForeignKey("es.payment.id"),
    nullable=True,
    index=True,
)