Skip to content

[FIX] l10n_sk_hr_payroll: retain individual social fund bases for MVP - #37

Closed
votrelec wants to merge 5 commits into
Data-Dance:19.0from
votrelec:fix/sk-mvp-fund-bases
Closed

votrelec wants to merge 5 commits into
Data-Dance:19.0from
votrelec:fix/sk-mvp-fund-bases

Conversation

@votrelec

@votrelec votrelec commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Regular OCA payroll currently exports GROSS into every MVP assessment field. A EUR25,000 wage therefore exports EUR25,000 even for capped funds, and pensioner/student agreements export positive bases for exempt funds. This change makes the salary rules and retained monthly evidence use the same engine-neutral per-fund assessment helper, and makes MVP consume that evidence.

OOP is deducted before the applicable cap. Accident insurance remains uncapped; guarantee insurance does not use OOP. Employee/employer caps remain distinct for partial employment. PFP attributes are omitted when inapplicable. MVP and VPP read retained historical regularity, so a later HR-profile edit does not route historical pay into both declarations.

Confirmation checks effective versions, dated parameters, work/input rows and the actual salary-rule results, including both skip-compute settings. Confirmed sources remain protected after cancellation. Employee non-key epochs coordinate version inserts/edits and salary sources with confirmation under PostgreSQL repeatable-read without conflicting with deferred employee foreign keys. Independent monthly payslips cannot consume the same OOP/cap twice. Native refund bookkeeping and a subsequent replacement remain available; a bookkeeping refund alone is not a complete corrective monthly declaration.

The base helper has no payroll-engine dependency. The OCA adapter implements the retained-source hooks; the MVP/VPP modules remain engine-neutral. Engines without the hook keep their existing rendering: this PR does not claim to fix or certify the proprietary engine. Existing filed XML is preserved. Missing legacy OCA evidence requires an explicit reviewed compatibility adapter instead of reconstructing a base by dividing rounded premiums. Allocation/correction adapters can supply their own cumulative source and filter effective replacements. A within-month change of insurance profile requires separate consolidation support and is refused rather than silently merged.

Validation on Odoo19 in Docker:

  • The original clean installation reproduced three wrong-base failures: high capped employment, old-age employment and a student agreement under OOP.
  • Final clean base/OCA/MVP/VPP assembly: 240 tests, 0 failures/errors, including real independent-cursor version-update/version-insert retries and deferred-FK compatibility.
  • Covers OOP before the cap, uncapped accident insurance, pension exemptions, partial-month employee/employer caps and insured days, two old-age agreements of EUR200/10 hours each, ordinary regular DoVP, historical MVP/VPP disjointness, copy/refund/cancellation and salary/source mutation controls.
  • Actual HTTP workflow with the standard OCA Payroll Officer role repeated twice: confirmation/retry, three employee rows, official bundled MVPP-v2026 XSD validation, reset/regeneration with identical XML bytes, Slovak fields_get and loaded Python UserError controls. The officer inherits HR-manager rights under OCA's existing policy; no system-administrator or Payroll Manager group was granted.
  • Native Odoo POT exports and Slovak merges for both affected catalogs, with no missing active translations. EN/SK source docs and changelogs describe compatibility and correction boundaries.
  • Ruff0.13 checks/format pass for the new source. The pre-existing large test_sk_payroll.py retains its three existing E741 names and original formatting; its changed refund scenario uses the real refund_sheet API. The private documentation generator is unavailable in this public checkout, so no generated-page/strict documentation build is claimed.

These are calculation, lifecycle, source-consistency and schema checks; no actual authority filing or payment was made. Legal basis: sections138 and138a of Act461/2003; the verified 2026 examples use the corresponding dated parameters.

A further integration check reproduced a cent discrepancy for prorated income: the rule category retained765.217391 while the payslip/ledger recorded765.22. The shared fund helper now derives the currency-rounded income before statutory base rounding. The added native case verifies765.22 of pension base and107.13 employer premium. The final clean240-test suite passes; existing posted history is not recalculated.

Ordinary nonzero remuneration outside the employment period must use a reviewed historical income allocation; it cannot be retained as a regular monthly social-insurance source. The added lifecycle case retains an unconfirmed calculation, records the ended employment before confirmation and refuses the ordinary monthly source.

Updated on accepted upstream sync7bf7b663: the full payroll/base/OCA/MVP/VPP suite passes240 tests, and the real officer HTTP/Slovak/XSD workflow passes twice with identical XML bytes. Cooperating payroll features can add JSON-compatible retained inputs via _l10n_sk_payroll_extra_source_facts; confirmation checks them even when recomputation is disabled. One independent extension-evidence case is included. Original confirmed sources remain unchanged.

Share capped/OOP assessment arithmetic with OCA salary rules; retain confirmed monthly facts for per-fund MVP and historical regularity in MVP/VPP. Coordinate sources and confirmation under repeatable-read, preserve native refunds and expose adapter hooks for reviewed corrections. Validate with 195 native tests and repeated ordinary-officer Slovak HTTP/XSD workflows.

Assisted-by: OpenAI Codex
A prorated rule category can retain fractional cents while the payslip and ledger record a currency-rounded GROSS. Derive the actual monetary income before applying statutory assessment-base rounding; verify 765.22 income and 107.13 employer pension premium. The clean native assembly passes 196 tests.

Assisted-by: OpenAI Codex
Keep ordinary monthly evidence from accepting nonzero remuneration outside its insured relationship. Cover unconfirmed historical income, skip-compute confirmation and chart/journal setup with installed accounting.

Assisted-by: OpenAI Codex
Validate optional feature facts through the same monthly retained source before skip-compute confirmation. Clean198 tests and actual officer HTTP/SK/XSD pass.

Assisted-by: OpenAI Codex
Retain accepted sickness entitlement and average-time guidance alongside the retained-source extension hook.

Assisted-by: OpenAI Codex
@Rad0van

Rad0van commented Nov 10, 2026

Copy link
Copy Markdown
Member

Thank you for this. Writing the per-fund bases into the MVP is the right fix, and the arithmetic matches Act 461/2003. The OOP comes off before the maximum base (§ 138a), and only for pension, disability and the reserve fund. Accident insurance stays uncapped and guarantee insurance takes no OOP. Only the employee cap is prorated for a part-month, which matches what our engine already does under § 138 ods. 13. The dated OOP values (200 € to 2026, 300 € from 2027) are the same in both engines. The rule's premium flooring and social_premium() agree exactly for two-decimal bases and rates.

We applied the branch on current 19.0. The only conflicts were in the version lines, the changelogs and the docs, because #39/#40 have been merged since. We ran it under sk_SK on both engines, compared against a 19.0 baseline, and also ran your branch head as published. On Enterprise the existing MVP/VPP suites are unchanged (0 failures). On Community, see point 7 for the test results.

The main question is how this fits the design we agreed in #25 and asked for on #34. Several of the points below depend on the answer.

Design

  1. One recorded-bases mechanism for every fund, shared with [ADD] l10n_sk_hr_payroll_health: shared assessments and current text514 #34. On [ADD] l10n_sk_hr_payroll_health: shared assessments and current text514 #34 we asked for one per-fund record, {fund, base, rate, amount, side}, whose shape and pure calculation live in l10n_sk_hr_payroll_base. Every declaration would read it through a single accessor in l10n_cssk_payroll_declaration_base. This PR adds a second design for social insurance only:

    • l10n_sk_social_assessment is an OCA-only JSON field keyed by the MVP's XML attribute names (vzNp, vzZecSp, …), not by fund. Rate and amount are not stored per fund, and the side is implied by the code.
    • The MVP reaches it with getattr(slip, "_l10n_sk_mvp_fund_bases"), a method named after one declaration, instead of a declaration-base accessor.
    • [ADD] l10n_sk_hr_payroll_health: shared assessments and current text514 #34 has its own JSON blob (l10n_sk_health_assessment_snapshot) with its own source facts, confirmation check and lock.

    If both merge as they are, we end up with two blobs, two confirmation paths and two readers. That is exactly the outcome we wanted to avoid. We propose:

    • (a) l10n_sk_hr_payroll_base defines an abstract mixin (for example l10n.sk.payslip.fund.mixin). It holds one JSON field with a list of {fund, side, base, rate, amount, extra} plus policy, facts and salary (your current envelope, unchanged in spirit). It also holds the pure helpers (assessment_base, social_premium, the fund/side table) and the generic checks: identity, salary facts, and "current" against a rebuild. Health is one fund, and its OP/insurer/calendar facts go in extra. The mixin needs no payroll dependency, because each engine bridge does _inherit = ["hr.payslip", "l10n.sk.payslip.fund.mixin"].
    • (b) The employee/version coordinator (social_source.py) uses only hr.employee and hr.version, so it can move to l10n_sk_hr_payroll_base as it is. [ADD] l10n_sk_hr_payroll_health: shared assessments and current text514 #34's calendar lock can use the same coordinator.
    • (c) l10n_cssk_payroll_declaration_base gets _payslip_fund_records(slips). It returns the records per payslip, plus the list of payslips that have none, so each declaration can apply the policy in point 2.
    • (d) MVP/VPP map fund to attribute in their own module, so vzNp etc. do not leak into the payroll layer.

    We suggest this PR introduces (a) to (d) with the social funds. [ADD] l10n_sk_hr_payroll_health: shared assessments and current text514 #34 then rebases its health fund onto it.

  2. Payslips without recorded bases: the agreed policy is different. Since 2026-11-10 the rule is: the monthly annexes (MVP, VPP, health) fall back to the gross-based figures and show a visible warning that names the payslips concerned. ELDP and corrective filings refuse until those payslips are recomputed. This PR refuses the MVP instead. We checked this with a real upgrade: install 19.0, confirm a March 2026 payslip, upgrade to this branch, then create the March MVP. The result is Review missing retained social-insurance bases before creating a new monthly declaration. (l10n_sk_hr_payroll_oca/models/social_assessment.py:322-327, reached from _l10n_sk_mvp_employee_fund_bases). At the same time, compute_sheet() on that payslip raises Retain confirmed payroll; use a payroll correction… (lines 289-304), and the compatibility adapter the description mentions does not exist. So after upgrading, nobody can file an MVP for any month whose payslips were confirmed before the upgrade, including a late MVP for an earlier month. Please:

    • fall back to the current gross-based row for payslips without a record, with a warning (a message, plus a chatter note listing the payslips);
    • keep the refusal for corrective MVPs (and later ELDP);
    • test both cases, using a payslip confirmed with the evidence column empty.
  3. A month with a correction cannot be filed. _l10n_sk_mvp_employee_fund_bases refuses whenever an employee has more than one payslip in the period and any of them carries evidence. Your own test test_fund_bases_native_refund_preserves_original_and_needs_declaration_correction asserts that a refund makes the MVP fail. Together with point 2 and the write/state locks on confirmed payslips, there is then no path from a payroll error to a filed MVP for that month. The same applies to a regular payslip plus a separate bonus payslip, which many OCA users run. We understand the reason (the OOP and the cap must not be consumed twice). Please consolidate instead of refusing: sum the records per employee and fund, net credit notes against their originals, and apply the cap and the OOP once to the combined income. Refuse only what genuinely cannot be combined, such as a change of profile within the month. If that is too much for this PR, fall back with a warning as in point 2, rather than blocking the filing.

  4. The VPP is not fixed. l10n_sk_hr_payroll_vpp/report/ still writes the same GROSS into all eleven vz* attributes. Evidence is only retained when l10n_sk_income_is_regular() is true (social_assessment.py:110-119). Pensioners and students on agreements, the example in your description, mostly have irregular income, so they appear on the VPP and still report positive bases for exempt funds. Please record the bases for irregular agreements too, and switch the VPP to them in the same way as the MVP.

  5. Record what the rule charged, rather than rebuilding it afterwards. _l10n_sk_build_social_assessment recomputes the bases from the GROSS line after compute_sheet(). If a single fund line differs by a cent, it stores False (social_assessment.py:272-279), and confirmation then refuses the payslip (line 322). So a company that adjusts one of these rules, or adds a rule to the GROSS category (the rules read categories.GROSS, the rebuild reads the GROSS line total), can no longer confirm payroll at all. Please let each fund rule record its own base, rate and amount: a dict in the rule's local context that the bridge persists after computation. Keep the rebuild only as a consistency check that warns. A rule that records nothing would then appear as "no record" and follow the policy in point 2.

Correctness

  1. Enterprise output changes. "Engines without the hook keep their existing rendering" is not quite the case. On Enterprise every row now gets vzPfp and pfpZamtel where it had none. Because there is no record, vzPfp falls back to GROSS. For a 25,000 € wage in March 2026 we get vzPfp="25000.00", while the capped base is 16,764.00. Please omit both attributes when no recorded base exists. We will do the Enterprise bridge ourselves at merge.

  2. Tests.

    • With sk_SK loaded, 11 of the new MVP tests fail only because assertRaisesRegex matches the English text of the message, and the Slovak catalogue translates it. Please run them with lang="en_US" in the context, or match something that does not depend on the language.
    • test_fund_bases_partial_month_preserves_distinct_caps_and_days fails here even on your branch head in English: GROSS is 60000.0, not 25000. On our setup (OCA payroll 19.0, current), get_worked_day_lines() for that version returns WORK100 with 12 days and 96 hours (16 to 31 March), even though contract_date_end is 20 March. Please create the worked-day line explicitly in the test, or tell us which OCA payroll revision you ran against.
    • test_social_source.py commits real records through separate cursors. Each run leaves six res.partner rows behind (the company and work-contact partners survive the cleanup). Please remove those as well. Also wrap the expected serialization failures in mute_logger("odoo.sql_db"), because CI shows them as ERROR … could not serialize access due to concurrent update.
    • Coverage on the touched modules is 94%. The untested money and compliance paths, by risk: the refusal of a change of profile within the month (social_assessment.py:189); the version/company mismatch (153); retained evidence that no longer matches the payslip (340); writing immutable fields on a confirmed payslip (80); negative GROSS (250); and the lock taken on hr.version.unlink (social_source.py:68-70).
  3. Concurrency scope. Every hr.version create, write and unlink now takes FOR NO KEY UPDATE on the employee and bumps a counter with raw SQL. This happens in every company and every country, including Czech employees in a mixed installation, and for edits that have nothing to do with insurance. The mechanism is sound under REPEATABLE READ, but the retry only exists for HTTP/RPC requests. Crons, imports and scripts that write versions will now get SerializationFailure where they did not before. Please:

    • restrict the lock to SK companies and to the fields that feed the assessment;
    • say in the docstring that callers outside a request must handle the retry themselves.

Conventions

  1. Changelogs.

    • In all four modules the new version sections are appended at the end of the file, below the oldest entry (base line 59, MVP 96, VPP 99, OCA 767).
    • They are bare bullets with no Added/Changed/Fixed subsections, and the same sentence is copied into all four modules.
    • In l10n_sk_hr_payroll_oca, 19.0.1.26.1 is a bullet under Unreleased while 19.0.1.26.0 is a heading. The module's Carry-over to 18.0 section also needs a "not yet on 18.0" entry for this change.
    • The VPP gets a patch-level bump (19.0.1.2.1) for a change in behaviour.
  2. Unrelated reformatting. l10n_sk_mvp.py and l10n_sk_vpp.py are reformatted as whole files, which hides the real change among about 150 lines of rewrapped code. Please keep the diff to the lines you change.

  3. Legal comments. Two citations were removed from the rules: "§ 4 ods. 4" for the guarantee exemption, and "§ 136 písm. b)" for the unemployment rate variant. Please keep them next to the code that now implements them.

  4. Missing spaces before numbers, again in comments, docs and commit text:

    • "§138" in the twelve rule comments and in the social_assessment.py docstring;
    • "Act461/2003";
    • "e.g.765.217391 ->765.22" in hr_version.py;
    • "EUR25,000" and "as765.22; its14%" in the docs;
    • "capacity2.5h/week" in a test;
    • "Clean198 tests" in a commit body.

    Please write "§ 138", "25 000 €" and so on.

  5. The last commit ("Refresh fund documentation and catalogs after accepted upstream sync") has no [FIX]/[IMP] tag.

  6. Seasonal OOP. The seasonal DoPČ OOP parameter (l10n_sk_dohoda_oop_seasonal, 762 € in 2026) exists in both engines but no rule uses it. That gap predates this PR. Still, the record shape in point 1 should allow a deduction that applies to a different set of funds, so that adding it later does not need a new design.

Suggested split

The PR would be easier to land in two parts, each mergeable on its own. (a) The shared record mechanism with the social funds, the OCA bridge, the fallback/refusal policy and consolidation (points 1 to 5). (b) The confirmation and source-locking controls (point 8, plus the locks on payslip children and state). (b) is where most of the new restrictions on existing payroll workflows are, and we would like to review it separately.

@votrelec

votrelec commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you for the detailed review and for exercising both engines. I have read all fourteen points. The published head still has the old split storage; I am replacing that design rather than asking you to merge two evidence mechanisms.

The local rework already captures each rule's actual base/rate/amount for both health and social funds, including irregular agreements, and uses a common declaration reader. It retains the old evidence read-only instead of requiring confirmed historical payslips to be recomputed. The monthly-original warning policy and native original/refund/replacement path are also being exercised. This is still work in progress, not a claim that the revised PR is ready.

Following the clarification in #34, the local base now owns the abstract mixin and generic checks, while the engine bridge owns the JSON/storage fields. The declaration framework exposes the plural accessor. VPP reads its eleven actual fund bases; historical ELDP reads employee pension bases. Missing evidence uses the named legacy warning for monthly originals and historical original ELDP, with strict corrective filings. Missing metadata from a customised rule no longer blocks payroll confirmation; inconsistent evidence still raises. XML attribute mappings stay in each declaration.

The shared Community suite passed 331 tests and the base without an engine passed 64 tests. A real model upgrade retained an existing confirmed payslip's JSON, confirmation timestamp and salary facts, and both archived XML hashes. This does not establish cumulative multi-payslip payroll correctness: independent monthly sources still need the agreed warning policy until a reviewed cumulative calculation exists. I will submit the core as a new PR referencing #34 and #37, followed by the dependent calendar/declaration changes; these local changes are not yet ready for review.

I will keep the confirmation/source-locking changes in a separate reviewable contribution, restrict the coordinator to relevant Slovak sources, and cover non-request retry/cleanup and language-independent fixtures. I have also recorded the requested changelog, formatting, citations and seasonal-deduction extensibility changes.

For the test-revision question: the Community runs use OCA/payroll 19.0 at 2eca6caafc74d4a592ee0ca75606b4c6e3ce75b9, with the worked-time fix from #330 (b97a09822bd5a2836c2436cb4be5ef0dc8164ba7) and the refund-hook changes from #332. The partial-month MVP fixture now supplies explicit worked hours, rather than relying on the worked-day boundary fix.

There is one additional small statutory rounding fix in #42: § 138(13) daily-cent flooring before multiplying a partial month's days. Its base-only tests and actual OCA premium test pass independently of this rework. It does not alter employer limits or historical records.

@Rad0van

Rad0van commented Nov 17, 2026

Copy link
Copy Markdown
Member

Closing this one as superseded: the per-fund bases it kept for the MVP are now recorded natively by the shared fund core from #43 (merged into our 19.0 as 7e880561, with the Enterprise recorder since), and the OOP-before-maximum part landed as #48. A declaration that files from the recorded bases will come with your stacked work (votrelec#9 onwards). Thank you.

@Rad0van Rad0van closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants