cadrumo.application.modelo.profile_readiness_gate module

Profile readiness gate for filing-grade modelo work.

Loads the active domain.user_profile.values.UserProfileRecord, builds a application.user_profile.commands.ProfilePreflightReport, projects local-work applicability through domain.deadlines.models.TaxpayerProfile, and raises application.modelo.action_errors.ModeloProfileReadinessError before filing-grade work proceeds when required profile facts are missing. The revision-specific preflight branch may receive a ModeloRevision that has already been resolved by an operator-facing readiness surface. The same gate also refuses Modelo 130 and Modelo 303 target periods whose date span ends before the profile’s censo.activity_start_date; those pre-activity periods have no filing obligation and must not produce stale work, calculation, verification, filing, or export state.

See also

require_profile_ready_for_work_unit():

Replays the same readiness checks for an existing WorkUnit.

application.user_profile.commands.ProfilePreflightReport:

User-profile preflight result consumed by this application gate.

BLOCKING_APPLICABILITY_VERDICTS

Shared with work_create_policy, which runs the same applicability block ahead of work-unit provisioning; kept public so that cross-module use is a declared contract rather than a private-symbol reach.

modelo_work_profile_baseline_missing_paths(record, *, modelo=None)[source]

Return profile facts required before filing-grade work for a target.

Without a target this returns the profile-status baseline: every non-natural entity, an economically active natural person, and an incompletely declared natural person need an activity description. A natural person with declared non-business income needs only a tax id. Targeted Modelo 100 checks use the same distinction; all other targets retain the existing censo-activity baseline.

Parameters:
Return type:

tuple[str, ...]

modelo_work_profile_baseline_validation_issues(record)[source]

Return profile-status issues for universal modelo-work baseline fields.

Parameters:

record (UserProfileRecord) – Active domain.user_profile.values.UserProfileRecord checked against the filing-grade baseline.

Return type:

tuple[ProfileValidationIssue, ...]

Returns:

Tuple of application.user_profile.commands.ProfileValidationIssue instances for missing filing-grade baseline facts.

modelo_work_profile_preflight_report(*, record, modelo, revision_id, filing_year, period, revision=None, resolve_revision_when_missing=True, profile_decode_context, operation)[source]

Return the profile-field report enforced by the modelo work creation gate.

This combines the filing-grade baseline that every modelo work unit needs with the modelo/revision-specific profile selectors. Public readiness surfaces consume this function so they cannot claim profile readiness before application.modelo.work_lifecycle.create_work_unit() would reject the same active profile.

Parameters:
  • record (UserProfileRecord) – Active domain.user_profile.values.UserProfileRecord.

  • modelo (str) – Modelo code being checked.

  • revision_id (TypeAliasType) – Registry revision identifier for the target modelo work.

  • filing_year (int) – Filing year for the target period.

  • period (Period) – Target core.period.Period used for registry revision resolution and profile selector evaluation.

  • revision (ModeloRevision | None) – Optional ModeloRevision supplied when the caller has already resolved the target revision.

  • resolve_revision_when_missing (bool) – Whether to resolve the registry revision when revision is not supplied.

  • profile_decode_context (ProfileDecodeContext) – Decode context from the caller-held authority operation used to interpret the encrypted profile.

  • operation (PinnedAuthorityOperation) – Caller-held pinned authority operation used to select the target revision and profile schema.

Return type:

ProfilePreflightReport

Returns:

application.user_profile.commands.ProfilePreflightReport combining baseline, validation, and modelo/revision-specific missing requirements.

profile_activity_start_date(record)[source]

Read the effective censo.activity_start_date through the canonical projection.

Which of several live facts at one path is effective is owned by application.user_profile.projections.record_to_path_values(), which orders them by valid_from so the chronologically last window wins. Scanning declaration order answers a different question: a record whose later window was declared first resolves to the earlier date, and because this value decides whether a target period is refused as pre-activity, the disagreement fails open — a period before the effective activity start is admitted for work.

Core types: UserProfileRecord.

Return type:

date | None

Parameters:

record (UserProfileRecord)

modelo_applicability_refusal(*, record, bucket_id, modelo, operation)[source]

Return the local-work applicability refusal for a target, if any.

Parameters:
Return type:

tuple[str, dict[str, str]] | None

pre_activity_period_refusal(*, record, bucket_id, modelo, filing_year, period)[source]

Return the pre-activity lifecycle refusal for a target, if any.

Parameters:
Return type:

tuple[str, dict[str, str | int]] | None

load_modelo_work_profile(*, bucket_id, profile_decode_context)[source]

Load the bucket’s profile for modelo work, or None when no session serves it.

Return type:

ModeloWorkProfile | None

Parameters:
require_profile_ready_for_modelo_work(*, bucket_id, modelo, revision_id, filing_year, period, enforce_applicability=True, profile_decode_context, operation, profile=None)[source]

Refuse filing-grade modelo work when the active profile is not eligible.

Loads the bucket’s domain.user_profile.values.UserProfileRecord, evaluates modelo-specific profile requirements through application.user_profile.commands.ProfilePreflightReport, and then applies the pre-activity period check for lifecycle modelos whose obligation starts at censo.activity_start_date. Unlike require_existing_profile_baseline_ready_for_modelo_work(), this gate passes the live registry authority through both the baseline/validation refusal and the full preflight report, so a raised ModeloProfileReadinessError carries real legal_refs for every missing field the registry grounds - the memoised build_profile_grounding_index keeps the added per-call cost bounded on this hot path. profile is the record the calling command already loaded for this target; when omitted the gate loads it. Returns the record the gate checked, so a caller that let the gate load it passes that same record on instead of decrypting it again.

Return type:

ModeloWorkProfile

Parameters:
require_existing_profile_baseline_ready_for_modelo_work(*, bucket_id, modelo, filing_year, period, enforce_applicability=True, profile_decode_context, operation, profile=None)[source]

Refuse plainly incomplete existing profiles before registry work.

This early gate is used by application.modelo.work_lifecycle.create_work_unit() before the registry revision and period are validated. It catches missing baseline profile facts, local-work applicability refusals, and pre-activity lifecycle periods without requiring a resolvable ModeloRevision. Missing profiles still pass through so the later full readiness gate can raise the canonical missing-profile error. profile is the record the calling command already loaded; when omitted the gate loads it.

Return type:

None

Parameters:
require_profile_ready_for_work_unit(work_unit, *, enforce_applicability=True, profile_decode_context, operation, profile=None)[source]

Run the profile readiness gate for an existing work unit.

Calculation, verification, filing, and export services call this wrapper so a previously created WorkUnit is rechecked against the current domain.user_profile.values.UserProfileRecord before any filing-grade mutation proceeds. Returns the checked record.

Return type:

ModeloWorkProfile

Parameters: