Skip to content

Commit

Permalink
[ADD] payroll_rule_history
Browse files Browse the repository at this point in the history
  • Loading branch information
dreispt committed Jan 2, 2025
1 parent 01c86b2 commit 3fc1743
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions payroll_rule_history/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
11 changes: 11 additions & 0 deletions payroll_rule_history/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Payroll Rule History",
"version": "18.0.1.0.0",
"category": "Payroll",
"website": "https://github.com/OCA/payroll",
"license": "LGPL-3",
"author": "Daniel Reis, Odoo Community Association (OCA)",
"depends": ["payroll"],
"data": ["views/hr_salary_rule_views.xml"],
"maintainers": ["dreispt"],
}
2 changes: 2 additions & 0 deletions payroll_rule_history/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import hr_salary_rule
from . import hr_salary_structure
27 changes: 27 additions & 0 deletions payroll_rule_history/models/hr_salary_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from odoo import fields, models


class HrSalaryRule(models.Model):
_inherit = "hr.salary.rule"

date_start = fields.Date(string="Start Date")
date_end = fields.Date(string="End Date")

# TODO: remove from "payroll" as not used anymore
# def _recursive_search_of_rules(self):

def _get_all_rules_and_childs(self):
"""
Lists all rules and their childs at a provided date.
Used by the Payslip computation to find the applicable rules.
"""
rules = self
active_date = self.env.context.get("active_date")
if active_date:
rules = rules.filtered(
lambda x: (x.date_start <= active_date or not x.date_start)
and (active_date <= x.date_end or not x.date_end)
)
if rules.child_ids:
rules |= self.child_ids._get_all_rules_and_childs()
return rules
18 changes: 18 additions & 0 deletions payroll_rule_history/models/hr_salary_structure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from odoo import models


def HrPayrollStructure(model):
_inherit = "hr.payroll.structure"

def get_all_rules(self):
"""
@return: returns a list of tuple (id, sequence) of rules that are maybe
to apply
"""
# TODO: move to main "payroll module
# all_rules = []
# for struct in self:
# all_rules += struct.rule_ids._recursive_search_of_rules()
# return all_rules
rules = self.rule_ids._get_all_rules_and_childs()
return [(x.id, x.sequence) for x in rules]
3 changes: 3 additions & 0 deletions payroll_rule_history/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
42 changes: 42 additions & 0 deletions payroll_rule_history/views/hr_salary_rule_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<odoo>

<record model="ir.ui.view" id="hr_salary_rule_history_view">
<field name="model">hr.salary.rule</field>
<field name="inherit_id" ref="payroll.hr_salary_rule_view_tree_children" />
<field name="arch" type="xml">

<field name="category_id" position="after">
<field name="date_start" />
<field name="date_end" />
</field>

</field>
</record>

<record model="ir.ui.view" id="hr_salary_rule_view_form">
<field name="model">hr.salary.rule</field>
<field name="inherit_id" ref="payroll.hr_salary_rule_view_form" />
<field name="arch" type="xml">

<field name="active" position="before">
<field name="date_start" />
<field name="date_end" />
</field>

</field>
</record>

<record model="ir.ui.view" id="hr_payroll_structure_view_form">
<field name="model">hr.payroll.structure</field>
<field name="inherit_id" ref="payroll.hr_payroll_structure_view_form" />
<field name="arch" type="xml">

<field name="sequence" position="after">
<field name="date_start" />
<field name="date_end" />
</field>

</field>
</record>

</odoo>

0 comments on commit 3fc1743

Please sign in to comment.