cadrumo.domain.invoices.normalization module¶
Invoice payload normalization and validation helpers.
These helpers are the canonical implementation used by models; the
public invoice record definitions and derive_invoice_id remain there.
- normalise_invoice_dates(payload)[source]¶
Coerce every present date and datetime field on
payloadin place, and return it.
- normalise_invoice_counterparty(payload)[source]¶
Validate and normalise the counterparty country, tax id, and identification state in place.
- normalise_invoice_currency(payload)[source]¶
Normalise the ISO 4217 currency field in place, and return the payload.
- raise_first_invoice_violation(violations)[source]¶
Raise on the first
(violated, message)pair whose flag is true.
- require_optional_non_negative(value, message)[source]¶
Raise
messagewhenvalueis present and negative.
- require_equal(actual, expected, message)[source]¶
Raise
messagewhenactualdoes not equalexpected.
- normalise_invoice_monetary_fields(payload)[source]¶
Coerce every present monetary field on
payloadto Decimal in place, and return it.
- derive_invoice_id_when_complete(payload, *, derive_invoice_id)[source]¶
Derive and set
invoice_idonce every identity field is present, or refuse a mismatch.
- normalise_invoice_collections(payload, *, normalise_linked_transaction_ids)[source]¶
Normalise the linked-transaction and line collections in place, and return the payload.