aeat.core._period module¶
Canonical period code enumeration for filing periods.
Period codes represent the filing frequency and scheme for tax returns: - Quarterly: 1T, 2T, 3T, 4T (standard filing periods) - Instalment: 1P, 2P, 3P, 4P (corporate-tax/IS instalment periods) - Annual: 0A - Monthly: 01-12 (calendar months) - OSS/IOSS: EXT-1T, EXT-2T, EXT-3T, EXT-4T (extra-Union scheme) - Ad-hoc/Event: AD-HOC, EVENT-N (event-driven filings)
StandardPeriodCode is the canonical StrEnum for
the closed standard vocabulary (1T-4T, 1P-4P, 0A, 01-12). It includes both
calendar spans and instalment claves, so callers that need date boundaries
must still check Period.has_date_span(). RegistryPeriodCode
is the pydantic field annotation for the full registry union: standard
members plus extended OSS/IOSS literals, AD-HOC, and the open-ended
EVENT-N shape. Period combines one accepted code with a filing
year, and PeriodKind classifies the resulting cadence.
This module is the runtime counterpart to the registry
domain.calculations.registry.PeriodCode alias and
domain.calculations.registry.PeriodSelector schema. Registry
objects carry bare period tokens; application services that need a concrete
filing window compose those tokens with a year into Period.
Operator commands follow the same separated shape (--year YYYY --period
<AEAT-token>); any year-qualified filter mini-grammar is converted at the
CLI boundary before it reaches this model.
- class StandardPeriodCode(*values)[source]¶
Bases:
StrEnumCanonical enumeration of closed standard filing-period codes.
Quarterly, monthly, and annual members have calendar spans. Instalment members (
1P-4P) identify filing/payment events and intentionally do not imply a contiguous ledger date span.- Q1¶
- Q2¶
- Q3¶
- Q4¶
- P1¶
- P2¶
- P3¶
- P4¶
- ANNUAL¶
- JAN¶
- FEB¶
- MAR¶
- APR¶
- MAY¶
- JUN¶
- JUL¶
- AUG¶
- SEP¶
- OCT¶
- NOV¶
- DEC¶
- accepted_period_codes()[source]¶
Return the fully enumerable period codes.
The tuple includes
StandardPeriodCode, extended OSS/IOSS literals, andAD-HOC. It deliberately excludes the infiniteEVENT-Nfamily; pair it withaccepted_period_patterns()when building help text or parse-error guidance.
- accepted_period_patterns()[source]¶
Return human-readable period-code patterns, including open regex shapes.
- RegistryPeriodCode¶
Pydantic field annotation for bare registry period tokens. Use
Periodinstead when a filing year is known.alias of
Annotated[str,BeforeValidator(func=_validate_period_against_registry, json_schema_input_type=PydanticUndefined)]
- exception PeriodError(message=None, *, context=None, suggestion=None, translated_message=None)[source]¶
Bases:
AeatError,ValueErrorRaised when a
Periodis constructed from an invalid year/code.Subclasses
ValueErrorso pydantic validation and existing callers retain value-error compatibility while still routing through the registeredAeatErrorhierarchy required for production exceptions.- Parameters:
- Return type:
None
- code: ClassVar[ErrorCode]¶
- class PeriodKind(*values)[source]¶
Bases:
StrEnumCadence class of a filing period, derived from its registry code.
- QUARTERLY¶
- MONTHLY¶
- ANNUAL¶
- INSTALMENT¶
- EXTENDED¶
- class Period(**data)[source]¶
Bases:
BaseModelA filing period as one typed value: a year paired with a registry code.
Periodis the canonical, fundamental representation of “which filing period” across the whole application. It composes exactly two authoritative fields — thefiling_yearand the registry periodcode(aStandardPeriodCodemember such as1T/0A/03, or an extended union member such asEXT-1T/AD-HOC/EVENT-3) — and never a combined calendar string (2026Q1/2026-03/2026). Those calendar shapes are neither accepted inputs nor canonical outputs. The only display projection is the space-separated__str__()form ("2026 1T"), and normal inbound construction is from a(year, code)pair viafrom_year_and_code().The model is frozen and hashes by
(filing_year, code), so aPeriodis a drop-in dict key, set member, and equality target wherever a typed period is required. The ledger and aggregation boundary routes throughapplication.aggregation.aggregation_period_for_modelo(), then usescontains()as the single date-boundary authority.- Variables:
filing_year – Filing year carried separately from the registry token.
code – Bare
RegistryPeriodCodetoken validated against the registry period union.
- Parameters:
- filing_year: int¶
- code: RegistryPeriodCode¶
- classmethod from_year_and_code(year, code)[source]¶
Build a
Periodfrom a filing year and a bare registry code.- Parameters:
year (
int) – The filing year (e.g.2026).code (
str) – A bare registry period code — aStandardPeriodCodevalue (1T-4T/1P-4P/0A/01-12) or an extended union member (EXT-1T-EXT-4T/AD-HOC/EVENT-N). The code is validated against the registry union; a combined calendar string is refused.
- Raises:
PeriodError – When
codeis not an accepted registry period code oryearis outside the supported range.- Return type:
- classmethod from_string(value)[source]¶
Parse the canonical display string emitted by
__str__().Only the separated
"YYYY <registry-code>"display form is accepted. Combined calendar strings such as"2026Q1"or"2026-1T"are refused; this method is for display round-trips, not an alternate CLI or registry grammar.- Parameters:
value (
str) – Space-separated display string containing a four-digit filing year and a bare registry period code.- Return type:
- Returns:
A
Periodparsed from the canonical display string.- Raises:
PeriodError – When
valueis not the display form or contains an invalid registry period code.
- property year: int¶
Return the filing year (alias of
filing_year).
- property registry_token: str¶
Return the bare registry period code as a string (e.g.
"1T").Use this when calling registry APIs that expect the bare
domain.calculations.registry.PeriodCodetoken rather than a structuredPeriod.
- property standard_code: StandardPeriodCode | None¶
Return the
StandardPeriodCodemember, orNonefor extended forms.
- property kind: PeriodKind¶
Return the cadence class derived from the period code.
- has_date_span()[source]¶
Return whether the period maps to an inclusive calendar date span.
Quarterly, monthly, and annual periods cover a contiguous span of calendar dates. Instalment claves (
1P-4P) and the extended union members are filing/payment events, not calendar spans, so they returnFalseandstart_date/end_daterefuse for them.- Return type:
- property start_date: date¶
Return the inclusive first calendar date of the period.
- Raises:
PeriodError – When the period has no calendar span (
has_date_span()isFalse).
- property end_date: date¶
Return the inclusive last calendar date of the period.
- Raises:
PeriodError – When the period has no calendar span (
has_date_span()isFalse).
- contains(value)[source]¶
Return whether
valuefalls within this period’s inclusive span.- Raises:
PeriodError – When the period has no calendar span.
- Return type:
- Parameters:
value (date)