Skip to content

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

Open
CristianoMafraJunior wants to merge 1 commit into
OCA:18.0from
Escodoo:18.0-IMP-payroll_contract_advantages
Open

[18.0][FIX] payroll_contract_advantages: bound validation, data integrity and precision#287
CristianoMafraJunior wants to merge 1 commit into
OCA:18.0from
Escodoo:18.0-IMP-payroll_contract_advantages

Conversation

@CristianoMafraJunior

Copy link
Copy Markdown
Member

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

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @nimarosa,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot OCA-git-bot added series:18.0 mod:payroll_contract_advantages Module payroll_contract_advantages labels Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:payroll_contract_advantages Module payroll_contract_advantages series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants