Skip to content

[18.0][ADD] payroll_rule_tag: tag salary rules and use tag totals in computations - #290

Open
nimarosa wants to merge 2 commits into
OCA:18.0from
nimarosa:18.0-add-payroll_rule_tag
Open

[18.0][ADD] payroll_rule_tag: tag salary rules and use tag totals in computations#290
nimarosa wants to merge 2 commits into
OCA:18.0from
nimarosa:18.0-add-payroll_rule_tag

Conversation

@nimarosa

Copy link
Copy Markdown
Contributor

Adds payroll_rule_tag: Salary Rules can carry any number of Tags, and each tag's
total is exposed to salary rule computations as tags.<CODE>.

Tags are a more flexible alternative to Salary Rule Categories: a rule belongs to a
single Category, but can carry any number of Tags, and tags may freely overlap. The
typical use is grouping rules into calculation bases — "Taxable", "Social Security",
"Benefits" — and computing each base as the total of the rules carrying that tag,
instead of repeating a list of rule codes in every formula:

result = tags.TAXABLE

Extraction note

Extracted from #174 (author @dreispt) to allow individual review/merge. The original
[ADD] payroll_rule_tag commit is cherry-picked unchanged with its authorship
preserved; #174 bundles several unrelated modules, which is why this one never got
reviewed on its own.

Completed on top of the original module

Configuration and multi-company

  • optional Code field, so the identifier salary rules use no longer has to be the
    tag name
  • company_id plus a multi-company record rule, list/kanban/search views, and ACLs
    split between Payroll Officer (read) and Payroll Manager (full)

Fixes

  • salary_rules_ids declared an explicit relation table while hr.salary.rule.tag_ids
    left it implicit, so the two fields were backed by different tables instead of
    being the two sides of one relation: tagging a rule never showed up on the tag's
    Salary Rules page and # Rules stayed at 0. The fix drops the explicit parameters
    rather than adding them on both sides — hr.payslip.line prototype-inherits
    hr.salary.rule, so an explicit table on tag_ids is copied to it and the registry
    refuses to build with two models sharing one many2many schema.
  • the tag code fell back to the tag name, which is translatable, so a payslip
    computed in a language having a translation for the tag resolved to a different code
    than the one written in the rule. BrowsableObject returns 0.0 for an unknown key,
    so this silently produced a wrong amount instead of an error. The fallback now reads
    the source value.
  • two tags could resolve to the same code ("Net Pay" / "Net-Pay", or a code equal to
    another tag's normalized name) and silently accumulate into a single total. Added a
    constraint rejecting duplicate effective codes per company; the existing SQL
    constraints only caught exact matches.
  • the kanban view used the deprecated t-name="kanban-box", which warns on every view
    load in 18.0; migrated to the card API.

Tests — 24 tests covering tag defaults and code resolution (explicit code,
normalized name, language independence), the constraints, both sides of the rule/tag
relation, ACLs and the multi-company rule, and the payslip behaviour: totals per tag,
unknown tags evaluating to zero, untagged rules staying out, totals summing line totals
rather than unit amounts, archived tags dropping out, and recomputing a payslip not
doubling the totals.

Packaging — version reset to 18.0.1.0.0 (the module was never released), readme
fragments completed (DESCRIPTION / CONFIGURE / USAGE / ROADMAP / CONTRIBUTORS), and
es / es_AR translations added.

@dreispt this is your module — could you take a look?

@nimarosa

Copy link
Copy Markdown
Contributor Author

@dreispt @norlinhenrik @CristianoMafraJunior @pedrobaeza
Please any of you can review so i can merge it soon? I'm using it in production and consuming the PR but would be nice to ship it with payroll directly.

@pedrobaeza pedrobaeza added this to the 18.0 milestone Aug 29, 2026
@pedrobaeza

Copy link
Copy Markdown
Member

You should squash your commits into less of them, as they are not adding value for the final result.

@nimarosa
nimarosa force-pushed the 18.0-add-payroll_rule_tag branch from fe09f9a to df7e940 Compare August 31, 2026 11:51
@nimarosa

Copy link
Copy Markdown
Contributor Author

@pedrobaeza Done ;)

@nimarosa
nimarosa force-pushed the 18.0-add-payroll_rule_tag branch from df7e940 to 9063721 Compare August 31, 2026 11:59
@pedrobaeza

pedrobaeza commented Aug 31, 2026

Copy link
Copy Markdown
Member

Now you have squashed into one, removing @dreispt attribution. He should check as well the final state.

@pedrobaeza

Copy link
Copy Markdown
Member

I mean there should be at least 2 commits: Daniel's one, and yours.

@nimarosa

Copy link
Copy Markdown
Contributor Author

@pedrobaeza I left @dreispt attribution in the commit. But okay, I make two commits if you thinl it's better.

dreispt and others added 2 commits August 31, 2026 09:15
…ations

Add hr.salary.rule.tag: a tag that groups salary rules so payslip
computations can reference a total across the group instead of one rule at
a time (payslip_lines_tag.<code>), which is what advanced structures such
as final-liquidation or overtime computations need.

- New model hr.salary.rule.tag with a resolved, unique, language-independent
  code (explicit code field, falling back to a normalized name), enforced by
  a company-scoped SQL/Python constraint so two tags can never collide on
  the same effective code.
- hr.salary.rule <-> hr.salary.rule.tag is a proper many2many inverse pair
  (fixed the relation table mismatch that kept salary_rules_ids and tag_ids
  out of sync and salary_rules_count stuck at 0).
- Multi-company support: tags are company-scoped with an access rule
  restricting them to their own company.
- Kanban view migrated to the Odoo 18 "card" API (t-name="kanban-box" is
  deprecated and was logging a warning on every load).
- Security: access rights for users/managers and the multi-company record
  rule.
- Test coverage for tag defaults/code resolution, the uniqueness
  constraints, both sides of the rule/tag relation, access rights, the
  record rule, and the payslip tag-total behaviour (unknown tags, untagged
  rules, archived tags, recomputation).
- Spanish (es, es_AR) translations and the OCA packaging (readme
  fragments, roadmap, contributors).
@nimarosa
nimarosa force-pushed the 18.0-add-payroll_rule_tag branch from 9063721 to 4a4bfed Compare August 31, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants