aeat.application.aggregation._counterpart module

Modelo 347/349 counterpart aggregation for informativa declarations.

Used by _service, the per-modelo aggregation service. This is not the live calculate source mesh: standalone CounterpartObservation rows are currently operator-supplied to the aggregate surface, while calculation-facing source values use CalculationSourceResolution. When a modelo revision declares only one counterpart source family, the calculation resolver narrows the active ModeloRevision view before projecting the registry binding values.

Modelo 347 covers annual operations with third parties whose total exceeds the declaration floor. Modelo 349 covers intra-EU operations by member-state operation kind. Both aggregate per (source_kind, counterparty_nif, operation_kind) using the counterpart subset of the canonical source-kind taxonomy, then expose helpers such as declarable_counterparty_nifs_347() for consumers that need the 347 threshold decision.

class CounterpartObservation(**data)[source]

Bases: BaseModel

One typed observation for a 347 or 349 aggregator pass.

Parameters:
  • source_kind (CounterpartSourceKind)

  • source_object_id (str)

  • counterparty_nif (str)

  • counterparty_name (str)

  • counterparty_country (str)

  • operation_kind (str)

  • operation_period (str)

  • taxable_base (Decimal)

  • invoice_total (Decimal)

  • accrued_on (str)

  • groi_verified (bool)

  • nif_iva_verified (bool)

source_kind: CounterpartSourceKind
source_object_id: str
counterparty_nif: str
counterparty_name: str
counterparty_country: str
operation_kind: str
operation_period: str
taxable_base: Decimal
invoice_total: Decimal
accrued_on: str
groi_verified: bool
nif_iva_verified: bool
class CounterpartRollup(**data)[source]

Bases: BaseModel

One (source_kind, counterparty_nif, operation_kind) rollup row.

Parameters:
  • source_kind (CounterpartSourceKind)

  • counterparty_nif (str)

  • counterparty_name (str)

  • counterparty_country (str)

  • operation_kind (str)

  • observations_count (int)

  • total_taxable_base (Decimal)

  • total_invoice_total (Decimal)

  • requires_groi_check (bool)

  • requires_nif_iva_check (bool)

  • groi_ready (bool)

  • nif_iva_ready (bool)

  • declarable_readiness_satisfied (bool)

source_kind: CounterpartSourceKind
counterparty_nif: str
counterparty_name: str
counterparty_country: str
operation_kind: str
observations_count: int
total_taxable_base: Decimal
total_invoice_total: Decimal
requires_groi_check: bool
requires_nif_iva_check: bool
groi_ready: bool
nif_iva_ready: bool
declarable_readiness_satisfied: bool
class CounterpartAggregation(**data)[source]

Bases: BaseModel

347 / 349 counterpart aggregation output.

Parameters:
modelo: str
period: InstanceOf[Period]
rollups: tuple[CounterpartRollup, ...]
total_counterparties: int
total_taxable_base: Decimal
total_invoice_total: Decimal
aggregate_counterpart_347(observations, *, period)[source]

Aggregate Modelo 347 (operaciones con terceros, annual).

Filters to 347 operation kinds. Threshold gating (the €3,005.06 declaration floor) belongs to the modelo binding consumer; this aggregator returns raw per-counterparty totals.

Returns a CounterpartAggregation.

Return type:

CounterpartAggregation

Parameters:
aggregate_counterpart_349(observations, *, period)[source]

Aggregate Modelo 349 (operaciones intracomunitarias).

Filters to 349 intracomunitarias operation kinds. Rollups carry the additional NIF-IVA / GROI readiness gates: Spanish counterparties require GROI readiness and non-Spanish counterparties require NIF-IVA readiness.

Returns a CounterpartAggregation with rollups sorted by (source_kind, counterparty_nif, operation_kind).

Return type:

CounterpartAggregation

Parameters:
class CounterpartAggregationSourceResolver(*, observations=())[source]

Bases: object

Resolve counterpart-source bindings from operator-supplied 347/349 observations.

The resolver is deliberately repository-free: it wraps the existing CounterpartObservation aggregate surface and emits the source-mesh envelope used by calculation once a caller supplies those observations.

Parameters:

observations (Iterable[CounterpartObservation])

resolver_id
owned_sources
resolve(context)[source]
Return type:

CalculationSourceResolution

Parameters:

context (CalculationSourceContext)

declarable_counterparty_nifs_347(aggregation)[source]

Return counterparties whose full Modelo 347 total exceeds the declaration floor.

Return type:

frozenset[str]

Parameters:

aggregation (CounterpartAggregation)

declarable_for_347(aggregation, *, counterparty_nif)[source]

Return True iff a counterparty exceeds the 347 declaration floor across all cohorts.

Return type:

bool

Parameters: