pay.utils

Classes

_PriceBase

Price

A single price.

InvoiceItemMeta

InvoiceMeta

The metadata of a full invoice.

_InvoiceDiscountMetaBase

InvoiceDiscountMeta

Built-in immutable sequence.

Functions

round_amount(→ decimal.Decimal)

Rounds the given amount to the nearest multiple of base.

payments_association_table_for(→ sqlalchemy.Table)

Module Contents

pay.utils.round_amount(amount: decimal.Decimal, base: decimal.Decimal) decimal.Decimal[source]

Rounds the given amount to the nearest multiple of base.

class pay.utils._PriceBase[source]

Bases: NamedTuple

amount: decimal.Decimal[source]
currency: str | None[source]
fee: decimal.Decimal[source]
credit_card_payment: bool[source]
class pay.utils.Price[source]

Bases: _PriceBase

A single price.

The amount includes the fee. To get the net amount use the net_amount property.

__bool__() bool[source]
__lt__(other: Price) bool[source]

Return self<value.

__add__(other: Price) Self[source]

Return self+value.

__sub__(other: Price) Self[source]
__mul__(other: decimal.Decimal | float | SupportsIndex) Self[source]

Return self*value.

__rmul__[source]

Return value*self.

__str__() str[source]

Return str(self).

__repr__() str[source]

Return repr(self).

classmethod zero() Self[source]
as_dict() onegov.pay.types.PriceDict[source]
property net_amount: decimal.Decimal[source]
apply_discount(discount: decimal.Decimal) Self[source]
class pay.utils.InvoiceItemMeta[source]
text: str[source]
group: str[source]
unit: decimal.Decimal[source]
quantity: decimal.Decimal[source]
vat_rate: decimal.Decimal | None = None[source]
family: str | None = None[source]
cost_object: str | None = None[source]
extra: dict[str, Any] | None = None[source]
property amount: decimal.Decimal[source]
property vat: decimal.Decimal[source]
property net_amount: decimal.Decimal[source]
static total(items: collections.abc.Iterable[InvoiceItemMeta]) decimal.Decimal[source]
static total_vat(items: collections.abc.Iterable[InvoiceItemMeta]) decimal.Decimal[source]
add_to_invoice(invoice: onegov.pay.models.Invoice) onegov.pay.models.InvoiceItem[source]
refresh_item(item: onegov.pay.models.InvoiceItem) None[source]
class pay.utils.InvoiceMeta[source]

The metadata of a full invoice.

Contains the freshly generated invoice items, an optional rounding base and an optional reference to an already existing invoice, which may contain manually added items that need to be considered for the rounding.

Iterating over this yields the generated items plus, if necessary, an extra item that rounds the invoice total to a multiple of the rounding base.

items: list[InvoiceItemMeta][source]
rounding_base: decimal.Decimal | None = None[source]
invoice: onegov.pay.models.Invoice | None = None[source]
rounding_text: str = 'Rounding difference'[source]
property manual_total: decimal.Decimal[source]
property manual_vat: decimal.Decimal[source]
property rounding_item: InvoiceItemMeta | None[source]
__iter__() collections.abc.Iterator[InvoiceItemMeta][source]
__bool__() bool[source]
property total: decimal.Decimal[source]

The total amount including the rounding item as well as any manual items on an existing invoice, mirroring Invoice.total_amount.

property total_excluding_manual_entries: decimal.Decimal[source]

The total of the generated items and the rounding item, excluding manual items on an existing invoice, mirroring Invoice.total_excluding_manual_entries.

property total_vat: decimal.Decimal[source]

The total VAT including any manual items on an existing invoice, mirroring Invoice.total_vat.

total_changed() bool[source]

Whether the total differs from the existing invoice’s total, taking rounding into account. Manual items are included on both sides, since they are preserved on refresh.

class pay.utils._InvoiceDiscountMetaBase[source]

Bases: NamedTuple

text: str[source]
group: str[source]
discount: decimal.Decimal[source]
vat_rate: decimal.Decimal | None = None[source]
family: str | None = None[source]
cost_object: str | None = None[source]
extra: dict[str, Any] | None = None[source]
class pay.utils.InvoiceDiscountMeta[source]

Bases: _InvoiceDiscountMetaBase

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable’s items.

If the argument is a tuple, the return value is the same object.

apply_discount(total: decimal.Decimal, remainder: decimal.Decimal) InvoiceItemMeta[source]
pay.utils.payments_association_table_for(cls: type[onegov.core.orm.Base]) sqlalchemy.Table[source]