cadrumo.core.field_role module

The closed vocabulary a tabular column’s meaning is mapped onto.

A CSV or spreadsheet arrives with header names the product does not control: a real libro registro carries every field the invoice importer needs under Spanish names it has never seen, plus a retención column it has no slot for at all. The mapping step answers “what does this column MEAN”, once per file, against this closed set — never per row, and never over a cell value.

That closedness is the anti-fabrication control. Role assignment is an allow-list selection over these members, so the only thing the mapping step can emit is a member; deterministic code then copies each cell under the chosen mapping. A column whose meaning cannot be established maps to FieldRole.UNMAPPED and is reported, so a file is never refused whole for carrying a column the product does not know, and an unknown column is never quietly copied into a field it does not belong to.

Member values are byte-identical to the column tokens the tabular importers already accept, so a role resolves against an existing importer column without a second translation table in between. The set is deliberately WIDER than those importers: retención and the suplido/recargo/total terms of the arithmetic closure, and the bank-movement booked date and amount, are roles the product must be able to recognise in a source table even where no importer column exists for them yet.

The set spans two source shapes that are NOT the same document. Most members describe an invoice book; FieldRole.BOOKED_DATE and FieldRole.MOVEMENT_AMOUNT describe a bank statement, which has no issue date, no base and no total. They are declared separately rather than borrowed from the nearest invoice member because a role is a claim about MEANING, and a near-fit reused across shapes propagates the wrong claim downstream to every consumer that trusts the name.

The axis lives in core because its producers, the deterministic copy step and the operator-facing report of unmapped columns sit in different packages, and core is the only home all of them reach without depending on each other.

See also

FieldOrigin

The companion axis recording HOW a value was obtained; a cell copied under a role mapping is FieldOrigin.TABULAR_MAPPED.

class FieldRole(*values)[source]

Bases: StrEnum

What one column of a source table means.

Closed by construction: an unrecognised header resolves to UNMAPPED rather than widening the set at read time.

UNMAPPED

The column’s meaning was not established. Reported, never copied.

TRANSACTION_ID

Identifier addressing an existing ledger transaction.

COUNTERPARTY_NIF

The other party’s Spanish tax identifier.

COUNTERPARTY_NAME

The other party’s name as printed.

INVOICE_NUMBER

The issuer’s invoice series and number.

INVOICE_DATE

Date of issue.

BOOKED_DATE

Date a bank movement was booked to the account.

Distinct from INVOICE_DATE, which is a date of issue on a document the counterparty printed. A movement has no issue date, and reading a booked date under the invoice member is the quiet mislabelling this member exists to remove.

MOVEMENT_AMOUNT

The signed-in-source amount of one bank movement.

Distinct from GRAND_TOTAL, which is an invoice’s printed total and the figure the arithmetic closure is checked against. A movement is not an invoice and has no total, no base and no cuota to close over. Direction is carried by the ledger’s own direction axis, never by this value’s sign.

TAXABLE_BASE

Base imponible, before cuota.

IVA_RATE

The IVA rate the line was charged at.

IVA_AMOUNT

Cuota de IVA.

IVA_CATEGORY

The IVA treatment the row falls under.

IRPF_CATEGORY

The IRPF treatment the row falls under.

RETENCION_AMOUNT

IRPF withheld at source; subtracted from the total to reach cash.

RETENCION_RATE

The IRPF retención rate the document prints beside its withheld amount.

RECARGO_AMOUNT

Recargo de equivalencia charged alongside the cuota.

SUPLIDO_AMOUNT

sums advanced on the customer’s behalf, outside the base.

Type:

Suplidos

GRAND_TOTAL

The printed total the arithmetic closure is checked against.

CURRENCY

ISO-4217 currency of the row’s amounts.

COUNTRY_CODE

Counterparty country, which decides domestic versus not.

NOTES

Free-text description carried through without interpretation.

CLASSIFICATION

Business-versus-personal decision for the row.

CATEGORY_ID

Spending category the row is assigned to.

BUSINESS_PCT

Business-use percentage for a mixed-use row.

USAGE_RATIO_ID

Named usage ratio supplying the business percentage.