Skip to content

ccnl_engine.results

The types read from a result: its assurance, blockers, decisions and issues, the model limitations, the capability gaps, the runs a year left out, the ledger account kinds and the remittance lines.

Assurance and payability

Every result answers "can these amounts be paid as they are?" with is_payable, and says why not with blockers, one ResultBlocker per reason, each with a stable BlockerCode, the feature it concerns, a machine-readable detail, a remediation and the totals it leaves unreliable (ResultTotal: net_pay, employer_cost, or both). Both come from assurance, a ResultAssurance derived from the run.

is_payable holds when both totals are reliable. Each total also has its own answer: is_net_pay_payable (no blocker touches the net pay) and is_employer_cost_complete (no blocker touches the employer cost). An open limitation on an amount only the employer owes, such as the mètaSalute health fund of the Metalmeccanico CCNL, leaves the employer cost short and the net pay payable. period_employer_cost never includes the INAIL premium, which rests on the tariff rate of the employer, nor IRAP.

The assurance axes:

Axis Type Derived from
calculation CalculationStatus Worst status of the issues and decisions
coverage CoverageStatus The capability report
evidence EvidenceStatus Weakest provenance of the payable rules read
rulesets RulesetAssurance tuple The CCNL ruleset and every ruleset a payable rule was read from, with readiness; also result.rulesets
mode EngineMode The mode of the engine; operational adds ruleset_not_production blockers
payability Payability payable exactly when there is no blocker
limitations ModelLimitation tuple The known model simplifications that apply to the run; an open one with monetary impact yes or unknown is also an open_limitation blocker

A result is payable only when it raised no issue, every decision is final, the capability report has no gap and no unresolved requirement, no executed rule is assumed or missing no rule was supplied by the caller and no open model limitation with a monetary impact applies; in operational mode, also only when the CCNL ruleset is production. A derived rule lowers evidence but does not block. See Assurance for the rules.

The year result combines the assurance of its runs (each axis the worst, rulesets, blockers and limitations each once; payable only when every run is) and lists their issues in payment order, each issue once: one repeated on every run (same code and message) is listed at its first run.

result = engine.calculate_period(period_input)
if not result.is_payable:
    for blocker in result.blockers:
        print(blocker.code.value, blocker.feature, blocker.detail)

The calculation axis:

Status Meaning
final Every capability decided from known rules and facts.
provisional Computed, but a decision rests on an assumption that may change the amounts.
incomplete At least one amount could not be determined; do not pay as is.
rejected The inputs cannot produce a meaningful result.

Compare statuses with severity or CalculationStatus.worst(): the string values do not sort in severity order.

An incomplete result still carries amounts, but at least one of them is missing, not zero: for example a surtax whose table is unknown is withheld as 0, flagged by the issue regional_surtax_unknown or municipal_surtax_unknown, recorded by a decision with no amount and reported as a blocker, so the result is not payable. result.decisions records what each capability decided, e.g. the surtax and tax credit decisions described in Fiscal computation. The year result exposes the decisions of its periods in payment order.

Capability report

result.capability_report compares what the run executed with the capability registry of the tax year. Each feature is traced from what actually ran, never from the presence of an input:

  • the core stages (base salary, INPS, TFR, IRPEF) run on every period;
  • an event feature (overtime, welfare, ...) is computed only when one of its events posted a non-zero amount or took a decision, otherwise skipped;
  • every other feature follows its decisions: final is computed (a zero amount with its reason counts), provisional is partial, incomplete or rejected is unresolved, and no decision is not applicable.

Each registry entry declares an applicability predicate, and capability_report.scope gives the result for the run: applicable, not_applicable (the predicate is false, or the handler ruled it out) or outside_input (the request has no field for the fact that makes it apply). An applicable capability is a gap when it is unsupported (the engine does not compute it, e.g. residual leave on the run that closes the employment), unresolved (e.g. a surtax without a table), a partial_result of a capability implemented in full, or a partial_implementation that executed (sickness, family deductions). Every gap is a capability_not_computed blocker.

The gaps alone are a blocklist: a capability whose handler took no decision because a fact was left to its default looks not_applicable. An entry that declares applicability_facts (the residence for the regional and municipal surtaxes, the family composition for the family deductions) is therefore required in every run: it must be ruled out by a decision of the run or decided on the supplied facts, never on a default. Each such fact left to its default, on a run that did not rule the capability out, is an UnresolvedRequirement in capability_report.unresolved and a requirement_unresolved blocker. The report status is the coverage axis of the assurance: incomplete with an unresolved requirement, otherwise partial when every gap is partial and incomplete with any other gap.

ccnl_engine.results.PUBLIC_FACTS = MappingProxyType({'activity': 'EmployerProfile.activity', 'advances': 'TfrFundBalance.advances', 'advances_taxable': 'TfrFundBalance.advances_taxable', 'net_income_biennio': 'PriorYearTaxFacts.net_income_biennio', 'agricultural_zone': 'EmployerProfile.agricultural_zone', 'agreement_signed_on': 'BonusEvent.agreement_signed_on', 'allocation_pct': 'Dependent.allocation_pct', 'category': 'Employment.category', 'cohabiting': 'Dependent.cohabiting', 'contribution_history': 'Employment.contribution_history', 'contractual_funds': 'EmployerProfile.contractual_funds', 'fund_opt_ins': 'Employment.fund_opt_ins', 'current_year': 'PeriodInput.current_year', 'employment_income': 'PriorYearTaxFacts.employment_income', 'ended_by': 'EmploymentPeriod.ended_by', 'disciplinary_dismissal': 'EmploymentPeriod.disciplinary_dismissal', 'permanent_incapacity': 'EmploymentPeriod.permanent_incapacity', 'fis_reduction': 'EmployerProfile.fis_reduction', 'cigs_indotto': 'EmployerProfile.cigs_indotto', 'provincial_pay_element': 'EmployerProfile.provincial_pay_element', 'second_level_premium': 'EmployerProfile.second_level_premium', 'permit_carryover': 'EmployerProfile.permit_carryover', 'subsector': 'EmployerProfile.subsector', 'inps_sector': 'EmployerProfile.inps_sector', 'just_cause': 'EmploymentPeriod.just_cause', 'probation_until': 'EmploymentPeriod.probation_until', 'level_started_on': 'Employment.level_started_on', 'legacy_section_applicable': 'EmployerProfile.legacy_section_applicable', 'solidarity_fund_covered': 'EmployerProfile.solidarity_fund_covered', 'meal_benefit_days': 'PeriodFacts.meal_benefit_days', 'individual_income': 'ParentalLeaveEvent.individual_income', 'local_hourly_agreement': 'HourlyParentalLeaveEvent.local_hourly_agreement', 'installment': 'PersonalWithholding.installment', 'unused_deductions': 'ArrearsEvent.unused_deductions', 'hourly_pay_elements': 'PeriodFacts.hourly_pay_elements', 'naspi_case': 'EmploymentPeriod.naspi_case', 'full_time_weekly_hours': 'Employment.full_time_weekly_hours', 'naspi_exclusion': 'FixedTerm.naspi_exclusion', 'no_pay_due': 'AbsenceEvent.no_pay_due', 'opening_state': 'PeriodInput.opening_state', 'ordinary_hours_worked': 'PeriodFacts.ordinary_hours_worked', 'paid_holiday_days': 'PeriodFacts.paid_holiday_days', 'presence_days': 'PeriodFacts.presence_days', 'site_presence_days': 'PeriodFacts.site_presence_days', 'other_employers': 'InpsBaseYtd.other_employers', 'other_employers_additional_ivs': 'InpsBaseYtd.other_employers_additional_ivs', 'own_income': 'Dependent.own_income', 'pension_fund': 'Employment.pension_fund', 'renewals': 'FixedTerm.renewals', 'residency_eligibility': 'Dependent.residency_eligibility', 'revaluations': 'TfrFundBalance.revaluations', 'reference_period': 'ArrearsEvent.reference_period', 'roles': 'Employment.roles', 'sector': 'Employment.sector', 'seniority': 'Employment.seniority', 'apprenticeship_months': 'SeniorityFact.apprenticeship_months', 'short_absence_exempt': 'SicknessEpisode.short_absence_exempt', 'prior_worked_days': 'SicknessEpisode.prior_worked_days', 'agricultural_days': 'SicknessEpisode.agricultural_days', 'hospital_stays': 'SicknessEpisode.hospital_stays', 'serious_illness': 'SicknessEpisode.serious_illness', 'daily_contributions': 'SicknessEpisode.daily_contributions', 'inps_base': 'SicknessEpisode.inps_base', 'inps_recognized': 'SicknessEpisode.inps_recognized', 'contractual_daily_wage_by_year': 'SicknessEpisode.contractual_daily_wage_by_year', 'maternity_base_pay': 'MaternityLeaveEvent.maternity_base_pay', 'paternity_base_pay': 'PaternityLeaveEvent.paternity_base_pay', 'parental_base_pay': 'ParentalLeaveEvent.parental_base_pay', 'topped_up_days_before': 'ParentalLeaveEvent.topped_up_days_before', 'protection_ended_on': 'ParentalLeaveEvent.protection_ended_on', 'last_fixed_pay': 'ExtraordinaryLeaveEvent.last_fixed_pay', 'last_month_paid_days': 'ExtraordinaryLeaveEvent.last_month_paid_days', 'sickness_known_from': 'OpeningBalances.sickness_known_from', 'suspends_accrual': 'AbsenceEvent.suspends_accrual', 'tfr_fund': 'Employment.tfr_fund', 'tfr_quotas': 'OpeningBalances.tfr_quotas', 'tfr_treasury_fund': 'Employment.tfr_treasury_fund', 'pay_above_ccnl': 'PriorYearTaxFacts.pay_above_ccnl', 'extra_deduction': 'PensionFundEnrolment.extra_deduction', 'in_periodic_shift': 'OvertimeEvent.in_periodic_shift', 'supplementary_hours_before': 'OvertimeEvent.supplementary_hours_before', 'agreed_annual_hours': 'OvertimeEvent.agreed_annual_hours', 'multiweek_hours_before': 'OvertimeEvent.multiweek_hours_before', 'young_member': 'PensionFundEnrolment.young_member', 'support_contract': 'PensionFundEnrolment.support_contract', 'erc_amount': 'Employment.erc_amount', 'prior_extra_month_amount': 'Employment.prior_extra_month_amount', 'holiday_company_offset': 'Employment.holiday_company_offset', 'una_tantum_reduced_months': 'Employment.una_tantum_reduced_months', 'leave_balances': 'OpeningBalances.leave_balances', 'conventional_base': 'PensionFundEnrolment.conventional_base', 'public_end_of_service': 'Employment.public_end_of_service', 'public_life_insurance': 'EmployerProfile.public_life_insurance'}) module-attribute

ccnl_engine.results.AccountKind

Bases: StrEnum

The twenty-three logical accounts that partition a payroll pay period.

The three PENSION_FUND accounts hold what is paid to a complementary pension fund: the employee contribution withheld, the employer contribution and the TFR paid to the fund instead of accruing in the company. TFR_TREASURY_FUND holds the TFR the employer pays monthly to the Fondo Tesoreria INPS (L. 296/2006 art. 1 c. 756) instead of accruing it in the company. PERSONAL_WITHHOLDINGS holds what the employer withholds from the net pay for a third party: a garnishment, a salary assignment or a delegation (:mod:~ccnl_engine.personal_withholding.services).

Every entry of the tax and credit accounts is non-negative; the account gives the direction:

  • ORDINARY_TAX: IRPEF withheld, before any credit is offset;
  • TAX_REFUNDS: IRPEF refunded to the worker by the conguaglio;
  • SURTAX: regional and municipal surtax withheld;
  • SURTAX_REFUNDS: surtax withheld above what the conguaglio finds due (usually the municipal acconto), given back;
  • CREDITS: amounts paid to the worker that the withholding agent recovers as an F24 credit (trattamento integrativo, somma esente);
  • CREDIT_RECOVERIES: those amounts, or an ulteriore detrazione of an earlier year, taken back from the worker;
  • CREDIT_RECOVERY_SHORTFALL: a recovery of the run the pay could not cover, given back on the payslip and carried to the next runs.

ccnl_engine.results.BlockerCode

Bases: StrEnum

Stable machine-readable kind of a :class:ResultBlocker.

Attributes:

Name Type Description
CALCULATION_ISSUE

An issue was raised, or a decision is not final: an amount rests on an assumption, a fallback or a condition the worker must be told about.

MISSING_FACT

A fact the calculation needs was not supplied.

MISSING_RULE

An issue caused by a rule or data the engine lacks.

REQUIREMENT_UNRESOLVED

A capability required in every run was not ruled out by a decision of the run, and the fact that decides it was left to its default: a default never decides a capability.

CAPABILITY_NOT_COMPUTED

A capability the catalog promises was not computed, could not decide or came out partial.

RULE_SOURCE_WEAK

An executed capability read a rule whose provenance is assumed or missing, or no rule of the run carries a provenance record.

CALLER_SUPPLIED_RULE

The caller supplied a value in place of a rule of the bundle, so no source backs it.

RULESET_NOT_PRODUCTION

In operational mode only: a ruleset the run read is not production, or no ruleset of the run tracks a readiness tier.

OPEN_LIMITATION

An open model limitation whose monetary impact is yes or unknown concerns the run.

RUN_NOT_COMPUTED

In a competence or tax year only: a run of the plan was skipped because the bundle holds no base salary of its CCNL level on its competence date; the year is partial.

RULESET_CONFLICT

In a combined result only: two runs read the same ruleset id@version with a different hash, kind, readiness or confidence, so the version does not name one content.

ccnl_engine.results.CalculationDecision dataclass

What one capability decided in a calculation, and why.

Attributes:

Name Type Description
capability str

Catalog feature name, e.g. "regional_surtax".

status CalculationStatus

Status implied by this decision.

reason_code str

Stable machine-readable reason in lower snake case, e.g. "table_found".

rule str

Identifier of the rule applied.

rule_version str

Version of the rule applied, e.g. the tax year or the data bundle version.

inputs Mapping[str, Decimal | str]

Normalized inputs the decision was taken from. Copied and read-only after construction.

source SourceLocation | None

Normative source of the rule, when recorded.

amount Decimal | None

Amount produced by the decision; None when the decision yields no amount or the amount is unknown.

origin DecisionOrigin

Whether the engine applied the rule or the caller supplied it. A caller-supplied decision cites no source.

Raises:

Type Description
ValueError

When reason_code is not lower snake case, when capability, rule or rule_version is empty, when amount is not finite, or when a caller-supplied decision cites a source.

ccnl_engine.results.CalculationIssue dataclass

A condition that lowers the status of a calculation result.

Attributes:

Name Type Description
code str

Stable machine-readable identifier in lower snake case, e.g. "surtax_table_unknown". Callers may branch on it.

message str

Human-readable explanation for the caller.

status CalculationStatus

Status the issue implies for the result that carries it.

source SourceLocation | None

Normative source behind the issue, when one applies.

fact str | None

Name of the public input field whose absence raised the issue, e.g. "employment_income"; one of :data:PUBLIC_FACTS, None when the issue is not about a missing fact.

capability str | None

Capability whose amounts the issue concerns, e.g. "seniority"; None for a condition of the whole run (the opening state, the provenance of the rules). The assessment reports one blocker per cause of a capability.

cause IssueCause | None

What resolves the issue: :attr:IssueCause.FACT whenever fact is set (a cause given with it stands for the case without a fact, and is replaced); without fact required and one of :attr:IssueCause.RULE and :attr:IssueCause.CONDITION.

Raises:

Type Description
ValueError

When code is not lower snake case, fact is not one of :data:PUBLIC_FACTS, message is empty, or an issue without fact has no cause or the cause fact.

ccnl_engine.results.CalculationStatus

Bases: StrEnum

How far the calculation of a result can be relied upon.

It is the calculation axis of :class:~ccnl_engine.assurance.models.ResultAssurance; whether the amounts can be paid is the assurance payability, not this status.

Members are listed from least to most severe. Compare them with :attr:severity or combine them with :meth:worst; the string values do not sort in severity order.

Attributes:

Name Type Description
FINAL

Every capability decided from known rules and facts.

PROVISIONAL

Computed, but at least one decision rests on an assumption that may change the amounts once confirmed.

INCOMPLETE

At least one amount could not be determined.

REJECTED

The inputs cannot produce a meaningful result.

severity property

Rank of this status, 0 for final up to 3 for rejected.

worst(statuses) classmethod

Return the most severe status in statuses.

Parameters:

Name Type Description Default
statuses Iterable[CalculationStatus]

Statuses to combine, possibly empty.

required

Returns:

Type Description
CalculationStatus

The status with the highest :attr:severity, or

CalculationStatus

attr:FINAL when statuses is empty.

ccnl_engine.results.IssueCause

Bases: StrEnum

What resolves a :class:CalculationIssue.

Attributes:

Name Type Description
FACT

A fact of the request is missing: the caller supplies it.

RULE

The bundle or the engine lacks the rule or the data the amount needs: it is added to the engine, and until then the amount is computed outside it.

CONDITION

Anything else the message explains: an assumption, a figure the caller gave that differs from the rule, an amount left to a later run, an input whose absence another blocker already reports.

ccnl_engine.results.CapabilityGap dataclass

An applicable capability the run does not cover in full.

Attributes:

Name Type Description
feature str

The capability name.

implementation CapabilityImplementation

How the registry says the engine implements it.

observed str

Trace state of the run, "absent" when untraced.

kind CapabilityGapKind

Why it is not covered.

ccnl_engine.results.CapabilityScope

Bases: StrEnum

Whether a capability concerns the run.

Attributes:

Name Type Description
APPLICABLE

It applies: it must be computed for the run to be covered.

NOT_APPLICABLE

Its predicate is false for the case, or its handler ruled it out.

OUTSIDE_INPUT

The fact that makes it apply has no field in the request; a case with that fact is outside the engine input.

ccnl_engine.results.CoverageStatus

Bases: StrEnum

How far the run covers the capabilities that apply to it.

Members are listed from the best to the worst coverage.

Attributes:

Name Type Description
COMPLETE

Every applicable capability was computed in full.

PARTIAL

Every gap is a partial result or a partially implemented capability that executed.

INCOMPLETE

An applicable capability is unsupported, untraced or could not decide.

worst(statuses) classmethod

Return the worst coverage in statuses.

Returns:

Type Description
CoverageStatus

The worst status, or :attr:COMPLETE when statuses is empty.

ccnl_engine.results.DecisionOrigin

Bases: StrEnum

Where the rule behind a decision comes from.

Attributes:

Name Type Description
ENGINE

The engine applied a rule of the bundled data or of the law.

CALLER_SUPPLIED

The caller supplied a value (a rate, a multiplier, an amount) that stands in for a rule the engine would otherwise apply; no bundled source backs it.

ccnl_engine.results.EvidenceStatus

Bases: StrEnum

How far the payable rules a run read are backed by their sources.

The values are those of the rule provenance status, listed from the strongest to the weakest backing.

Attributes:

Name Type Description
VERIFIED

Every rule was checked by a named reviewer.

DERIVED

The weakest rule is taken from a cited location, unchecked.

ASSUMED

A rule is adopted without a located citation.

MISSING

A rule has no source, or no rule carries a record.

weakest(statuses) classmethod

Return the weakest of statuses, given as provenance values.

Returns:

Type Description
EvidenceStatus

The weakest status, or :attr:MISSING when statuses is empty:

EvidenceStatus

nothing backs a run whose rules carry no record.

ccnl_engine.results.LimitationStatus

Bases: StrEnum

Whether a limitation still holds.

Attributes:

Name Type Description
OPEN

The engine still computes the simplified amount.

RESOLVED

The model was corrected, with a source and a test.

UNSOURCED

A declared residual: a documented search of the law, the INPS and Ministry practice and the signed text found no source and no statutory default for the case. The engine still computes the simplified amount, so it keeps blocking the runs it concerns; it is listed apart from the open work.

AWAITING_PUBLICATION

The source is due by a known process on a known date (the minimi of a year, a budget law, an INPS circular): the runs it concerns keep blocking, and it is listed apart from the open work until that date (:class:AwaitedPublication); past it, it is open work again.

ccnl_engine.results.ModelLimitation

Bases: BaseModel

A known simplification of the engine, typed and executable.

Attributes:

Name Type Description
id str

Stable identifier: <ccnl id>/<variant> for a CCNL note, the bare variant name for an engine limitation.

capability str

Registry capability the limitation concerns.

variant str

Variant of the capability it concerns.

summary str

What the engine does differently, for a human reader.

monetary_impact MonetaryImpact

Whether it can change an amount.

status LimitationStatus

Whether it still holds.

rulesets tuple[str, ...]

Ids of the CCNLs it affects.

applies_when LimitationScope

The runs it concerns.

totals frozenset[ResultTotal]

The totals of a run it can make wrong: both by default, the employer cost alone for an amount only the employer pays.

source str

Where it is declared: the CCNL file or the engine module.

remediation str

What closes it.

searched tuple[SearchedDocument, ...]

The documents read, for an unsourced limitation only.

covers tuple[str, ...]

The payable rules (<file>#<path>) whose missing source the residual declares.

awaited AwaitedPublication | None

The publication due, for an awaiting limitation only.

blocks property

Whether it makes a result it applies to not payable.

Returns:

Type Description
bool

True for an open or unsourced limitation whose monetary

bool

impact is yes or unknown: a declared residual still

bool

computes the simplified amount.

awaited_on(today)

Whether, on today, it waits for a publication not yet due.

Returns:

Type Description
bool

True for an awaiting limitation whose expected_by is not

bool

past; an overdue one is open work again.

applies_to(facts)

Return whether the limitation concerns the run of facts.

An owed limitation concerns every run of an affected CCNL. Otherwise the capability must concern the run: a path limitation concerns it when the run traversed its path, whatever the CCNL; a run limitation when the CCNL is affected; an outside_input one never. The scope must match in every case.

Returns:

Type Description
bool

True when the limitation concerns the run.

ccnl_engine.results.MonetaryImpact

Bases: StrEnum

Whether a limitation can change an amount the engine computes.

Attributes:

Name Type Description
YES

In the cases it applies to, an amount is known to differ from the contract.

NO

No amount the engine computes from the bundle changes: the engine refuses the case, or reads the value from the caller.

UNKNOWN

An amount may differ; the contract reading or the source is not confirmed.

ccnl_engine.results.Payability

Bases: StrEnum

Whether the amounts of a result can be paid as they are.

Attributes:

Name Type Description
PAYABLE

Nothing blocks the amounts.

NOT_PAYABLE

At least one :class:ResultBlocker applies.

ccnl_engine.results.RemittanceColumn

Bases: StrEnum

F24 column an amount is reported in.

DEBIT = 'debit' class-attribute instance-attribute

"importi a debito versati": tax withheld or credit recovered.

CREDIT = 'credit' class-attribute instance-attribute

"importi a credito compensati": credit paid to the worker.

ccnl_engine.results.RemittanceLine dataclass

Total of one account and codice tributo over a set of entries.

Attributes:

Name Type Description
account AccountKind

Tax or credit account of the entries.

remittance_code str | None

Their codice tributo, None when not verified.

column RemittanceColumn | None

F24 column of a coded amount; None for an uncoded line or an account that is never remitted.

amount Decimal

Sum of the entries, in EUR.

ccnl_engine.results.ResultAssurance dataclass

Whether the amounts of a result can be relied upon and paid.

Attributes:

Name Type Description
calculation CalculationStatus

Worst status of the issues and decisions.

coverage CoverageStatus

Status of the capability report.

evidence EvidenceStatus

Weakest provenance of the payable rules read; missing when no rule carries a record.

rulesets tuple[RulesetAssurance, ...]

Assurance of the rulesets the rules were read from: identity, hash, readiness and confidence.

mode EngineMode

Payability policy the blockers were derived under.

payability Payability

:attr:Payability.PAYABLE exactly when :attr:blockers is empty.

blockers tuple[ResultBlocker, ...]

Every reason the amounts cannot be paid, in the order they were found.

limitations tuple[ModelLimitation, ...]

Model limitations that concern the run, open or resolved, whatever their monetary impact; those that block are also listed in :attr:blockers.

is_payable property

Whether nothing blocks the amounts: every total is reliable.

is_net_pay_payable property

Whether no blocker leaves the net pay unreliable.

is_employer_cost_complete property

Whether no blocker leaves the employer cost unreliable.

with_blockers(blockers)

Return the assurance with blockers added after its own.

Returns:

Type Description
ResultAssurance

The assurance, its payability decided again on every blocker.

combine(assurances) classmethod

Aggregate the assurance of several runs, e.g. those of a year.

Each axis takes its worst value; rulesets, blockers and limitations are listed once each, in the order they first appear. Rulesets that share an id@version but differ in content are all kept, and each such id@version adds a ruleset_conflict blocker.

Returns:

Type Description
ResultAssurance

The aggregated assurance.

Raises:

Type Description
ValueError

When assurances is empty, or mixes modes.

ccnl_engine.results.ResultBlocker dataclass

One reason the amounts of a result cannot be paid.

Attributes:

Name Type Description
code BlockerCode

Kind of blocker; callers may branch on it.

feature str | None

Capability the blocker concerns, None when it concerns the run as a whole (an issue, a missing fact).

detail str

Machine-readable specifics in lower snake case where the source allows: the issue code, the decision reason, the missing fact, the fact left to its default, the gap kind, the provenance status, the caller fields, the id of the ruleset short of production, the id of the open limitation, or the id of the run not computed.

remediation str

What removes the blocker, for a human reader.

totals frozenset[ResultTotal]

The totals the blocker leaves unreliable; both unless it concerns an amount that only one of them holds (an open limitation on an employer-only fund leaves the net pay alone).

ccnl_engine.results.ResultTotal

Bases: StrEnum

A total of a result that a blocker leaves unreliable.

Attributes:

Name Type Description
NET_PAY

The net pay of the worker.

EMPLOYER_COST

The employer cost of the result.

ccnl_engine.results.UncoveredRun dataclass

A run of a competence year that was not computed.

The bundle holds no base salary of the CCNL level on the competence date of the run: the pay tables start later, or the date falls in a gap the bundle declares. The year computes its other runs and is not payable (see :attr:blocker). The fields are those of the :class:~ccnl_engine.errors.MissingRuleError a run of that date raises, rebuilt by :attr:error.

Attributes:

Name Type Description
payment PaymentId

The run and the date it would have been paid.

ruleset str | None

Id of the CCNL whose rule is missing.

feature str | None

The rule with no value (base_salary).

as_of date

The date the rule was read on: the competence date.

gap_kind str | None

Kind of the declared gap, None before the rule starts.

detail str

Why the rule has no value on :attr:as_of.

remediation str | None

What the caller can do about it.

error property

The error a run of :attr:payment raises.

blocker property

The run_not_computed blocker of the run, detail its run id.

of(payment, error) classmethod

Return the run left out with the error a run of its date raises.

Returns:

Type Description
UncoveredRun

The run, with the fields of error.

ccnl_engine.results.UnresolvedRequirement dataclass

A required capability left undecided by a default.

Attributes:

Name Type Description
feature str

The capability, as named by the registry.

fact str

The request fact that decides whether it applies, left to its default, e.g. "facts.regione".

JSON form of a result

result_to_json writes a PeriodResult, a CompetenceYearResult or a TaxYearResult as JSON, with the same tagged values as a request: every field under result and, under derived, is_payable, is_net_pay_payable, is_employer_cost_complete, blockers and the totals, which a reader outside Python could not compute. The JSON is output only: a result is recomputed from its request, not read back.

ccnl_engine.results.result_to_json(result)

Return result as JSON text, with its schema and engine versions.

Decimals are written as strings and dates in ISO 8601. The JSON holds every field of the result under result and, under derived, is_payable, is_net_pay_payable, is_employer_cost_complete, blockers and the totals: paid_gross, payslip_lines, progressives and remittance_summary for a period, annual_gross, annual_net and annual_employer_cost for a year. It is output only: a stored result is read as JSON, and the engine recomputes a result from its stored request.

Returns:

Type Description
str

The JSON text of the result.

ccnl_engine.results.ExtraMonthProgress dataclass

The ratei of one extra month a payslip prints as maturati.

Attributes:

Name Type Description
kind ExtraMonthKind

Which extra month (tredicesima, quattordicesima).

payment_year int

Year the extra month of the window is paid in.

months Decimal

Ratei accrued in the window by the end of the run's month, 0 to 12 (whole months, plus the days of a day-based rule).

fraction Decimal

Share of a monthly pay those ratei are worth.

ccnl_engine.results.PayslipLine dataclass

A line of the payslip: a voce, its quantity and its two columns.

Attributes:

Name Type Description
voce str

The provider's code of the voce when its mapping names the engine code, else the engine code.

engine_code str

The engine code of the voce.

description str

What the line pays or withholds.

quantity Decimal | None

Quantity in :attr:unit, None for a statutory line (contributions, taxes) that has no pay item.

unit VoceUnit | None

Unit of :attr:quantity, None with it.

rate Decimal | None

Amount per unit, None when it has no quantity.

earning Decimal

Amount in the competenze column, zero otherwise.

deduction Decimal

Amount in the trattenute column, zero otherwise.

ccnl_engine.results.Progressives dataclass

The progressivi a payslip prints, after the run.

Attributes:

Name Type Description
tax_year int | None

Tax year of the cash amounts, None before any payment.

gross Decimal

Gross paid in the tax year.

taxable Decimal

IRPEF taxable income of the tax year.

inps_employee Decimal

Employee INPS contributions of the tax year.

irpef Decimal

IRPEF withheld in the tax year.

surtax Decimal

Regional and municipal surtax withheld in the tax year.

inps_base Decimal

INPS base of the runs of this employment of the competence year of the run.

tfr_accrued Decimal | None

TFR the runs of the competence year accrued with the employer, the run's own included; None for a year whose quotas an import left unknown.

extra_months tuple[ExtraMonthProgress, ...]

Ratei maturati of each extra month by the end of the month of the run.

ccnl_engine.results.VoceUnit

Bases: StrEnum

Unit a payslip line counts its quantity in.

Attributes:

Name Type Description
HOURS

Hours (straordinario, maggiorazioni).

DAYS

Days (assenze, malattia).

UNITS

The item quantity (one month, one rateo, one payment).

ccnl_engine.results.VoceSide

Bases: StrEnum

Column of the payslip a pay item belongs to.

Attributes:

Name Type Description
EARNING

Competenze, added to the gross.

DEDUCTION

Trattenute, taken from the pay.

EMPLOYER

A cost of the employer, outside the pay (contributions, TFR accrued).

FIGURATIVE

Shown for its effect on the bases or the tax, not paid (fringe benefits, welfare, the credits applied to IRPEF).

Comparing with another payroll

compare_totals compares the eight totals of a run with the payslip of another payroll computed from the same facts: build the request with request_from_json or the input types, run it, pass the other payroll's totals by name (TOTALS), and read one TotalDifference per total and whether the run is payable. The perimeter of each total is the one of the validation packets.

from decimal import Decimal

from ccnl_engine.results import compare_totals

comparison = compare_totals(result, {"net": Decimal("1527.84")})
for difference in comparison.differences:
    print(difference.total, difference.engine, difference.difference)

ccnl_engine.results.compare_totals(result, expected, *, tolerance=_CENT)

Compare the totals of result with expected, at tolerance.

The other output is, for example, the payslip a payroll provider computed from the same facts: build the request with :func:~ccnl_engine.inputs.request_from_json or the input types, run it, and pass the provider's totals. Only the totals named in expected are compared; see the perimeter of each in the trust pages.

Parameters:

Name Type Description Default
result PeriodResult

A run of the engine.

required
expected Mapping[str, Decimal]

The other output's value of each total to compare, keyed by a name of :data:~ccnl_engine.comparison.totals.models.TOTALS.

required
tolerance Decimal

The largest absolute difference that counts as a match.

_CENT

Returns:

Type Description
TotalsComparison

One difference per total, in the order of expected, and whether

TotalsComparison

the engine's result is payable.

Raises:

Type Description
InvalidInputError

When a name is not a total, a value is not a Decimal, or the tolerance is negative.

ccnl_engine.results.TOTALS = {'base_salary': _base_salary, 'gross': lambda r: r.period_gross, 'employee_contributions': _accounts(_A.EMPLOYEE_CONTRIBUTIONS), 'employer_contributions': _accounts(_A.EMPLOYER_CONTRIBUTIONS), 'tax': _accounts(_A.ORDINARY_TAX, _A.SURTAX, _A.SUBSTITUTE_TAX, _A.SEPARATE_TAX, minus=(_A.TAX_REFUNDS, _A.SURTAX_REFUNDS)), 'net': lambda r: r.period_net, 'tfr': _accounts(_A.TFR_ACCRUAL, _A.PENSION_FUND_TFR, _A.TFR_TREASURY_FUND), 'employer_cost': lambda r: r.period_employer_cost} module-attribute

ccnl_engine.results.TotalsComparison dataclass

The totals of a run compared with another output.

Attributes:

Name Type Description
differences tuple[TotalDifference, ...]

One entry per total compared, in the order given.

tolerance Decimal

The largest absolute difference that counts as a match.

payable bool

Whether the engine's result is payable as it is.

matches property

Whether every compared total is within the tolerance.

ccnl_engine.results.TotalDifference dataclass

One total of a run next to the value it is compared with.

Attributes:

Name Type Description
total str

Name of the total, a key of :data:TOTALS.

engine Decimal

What the engine computed.

expected Decimal

The value of the other output.

difference Decimal

engine - expected.

within_tolerance bool

Whether the difference is within the tolerance.