← Back to Pull requests

[18.0][FIX] payroll_contract_advantages: bound validation, data integrity and precision #287

Open
unknown opened this pull request with 360 lines diff across 4 files
View on GitHub
unknown unknown commented on Aug 17, 2026 23:38 UTC
Author

What's broken today

  • hr.contract.advantage._check_bound_limits() treats 0.0 as a real bound instead of

  • "no limit on that side". Any hr.contract.advantage.template left with the default
    (unset) lower_bound/upper_bound therefore rejects every non-zero amount,
    making the advantage type unusable until an admin discovers they must also fill in
    bounds that have no required flag or hint suggesting so.
  • Nothing prevents assigning the same advantage template twice on the same contract.

  • payroll_contract_advantages/models/hr_payslip.py builds a {code: amount} dict from
    contract.advantages_ids, so a duplicate line silently overwrites one amount with the
    other with no warning, and the resulting payslip total is wrong without any error
    being raised.
  • Nothing prevents two hr.contract.advantage.template records from sharing the same

  • code. That code is the key salary rules use to read the value (advantages.<CODE>),
    so a duplicate code makes two different advantages collide in the same computation.
  • hr.contract.advantage.contract_id is not required and has no ondelete, so

  • deleting a contract leaves orphaned hr.contract.advantage rows with
    contract_id = NULL instead of being cleaned up.
  • hr.contract.advantage.template allows saving a default_value outside its own

  • lower_bound/upper_bound, and allows lower_bound > upper_bound — an
    already-inconsistent template that only surfaces the problem later, when someone tries
    to use it.
  • amount (on the advantage line) and lower_bound / upper_bound / default_value

  • (on the template) use plain Float with no digits precision, unlike the rest of the
    payroll engine which consistently uses the Payroll (2 decimals) precision for
    monetary-like amounts.

    What this PR changes

  • hr_contract_advantage.py

  • - _check_bound_limits(): a bound of 0.0 is now treated as "not set", matching the
    common Odoo convention, instead of blocking every non-zero amount.
    - contract_id: now required=True, ondelete="cascade".
    - advantage_template_id: now required=True.
    - amount: now uses digits="Payroll".
    - New SQL constraint contract_template_unique: one template per contract.
  • hr_contract_advantage_template.py

  • - New SQL constraint code_unique.
    - New _check_bounds_consistency(): rejects lower_bound > upper_bound and a
    default_value outside the template's own bounds (same "0.0 = no limit"
    convention).
    - lower_bound / upper_bound / default_value: now use digits="Payroll".
  • Tests: 5 new test cases covering every rule above, plus one pre-existing test adjusted

  • (test_onchange_advantage_template_sets_default_amount) whose fixture value became
    inconsistent with the new bound-consistency check.

    cc @nimarosa @pedrobaeza

    Diff: 360 lines (+270 / -90) across 4 files Reviewer: nimarosa Review duration: 148638m
    All Vouch review confidence checks passed
    Residual risk 0.43 = Change Risk (0.73) × (1 − Review Confidence (0.41)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.73 · 360 lines diff across 4 files
    0.73
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    40%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.352
    Shallow Review Depth shallow_review_depth
    0.344
    Sensitive Paths sensitive_paths
    0.073
    Real PR Conversation Timeline
    1 comments
    "Review active on #287"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 40.9% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 72.8% (HIGH) · Higher = larger blast radius
    72.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 40.9% · Lower = rushed or shallow review
    40.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 43.0% · Moderate risk
    43.0%
    Repository