Skip to content

Commit 34225c1

Browse files
committed
[ADD] hr_holidays_accrual_by_tag: new module
1 parent e4623a1 commit 34225c1

12 files changed

Lines changed: 716 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
==========================
2+
HR Holidays Accrual By Tag
3+
==========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:6a371341422010f0c2c1103e2663fc7bdd9fdd42bb6af0640786c2805713fc1c
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr--holidays-lightgray.png?logo=github
20+
:target: https://github.com/OCA/hr-holidays/tree/16.0/hr_holidays_accrual_by_tag
21+
:alt: OCA/hr-holidays
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/hr-holidays-16-0/hr-holidays-16-0-hr_holidays_accrual_by_tag
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module manages automatically accrual allocations by employee tags.
32+
When a new employee is created, accrual allocations are created starting from active accrual plans, based on its tags.
33+
Adding tags later and removing them is also managed.
34+
35+
**Table of contents**
36+
37+
.. contents::
38+
:local:
39+
40+
Bug Tracker
41+
===========
42+
43+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-holidays/issues>`_.
44+
In case of trouble, please check there if your issue has already been reported.
45+
If you spotted it first, help us to smash it by providing a detailed and welcomed
46+
`feedback <https://github.com/OCA/hr-holidays/issues/new?body=module:%20hr_holidays_accrual_by_tag%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
47+
48+
Do not contact contributors directly about support or help with technical issues.
49+
50+
Credits
51+
=======
52+
53+
Authors
54+
~~~~~~~
55+
56+
* PyTech SRL
57+
58+
Contributors
59+
~~~~~~~~~~~~
60+
61+
* `PyTech <https://pytech.it>`_:
62+
63+
* Quirino Leone <quirino.leone@pytech.it>
64+
65+
Maintainers
66+
~~~~~~~~~~~
67+
68+
This module is maintained by the OCA.
69+
70+
.. image:: https://odoo-community.org/logo.png
71+
:alt: Odoo Community Association
72+
:target: https://odoo-community.org
73+
74+
OCA, or the Odoo Community Association, is a nonprofit organization whose
75+
mission is to support the collaborative development of Odoo features and
76+
promote its widespread use.
77+
78+
This module is part of the `OCA/hr-holidays <https://github.com/OCA/hr-holidays/tree/16.0/hr_holidays_accrual_by_tag>`_ project on GitHub.
79+
80+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "HR Holidays Accrual By Tag",
3+
"version": "16.0.1.0.0",
4+
"summary": "Automates accrual plan assignment based on employee tags.",
5+
"category": "Human Resources",
6+
"author": "PyTech SRL, Odoo Community Association (OCA)",
7+
"website": "https://github.com/OCA/hr-holidays",
8+
"depends": ["hr", "hr_holidays"],
9+
"data": [],
10+
"installable": True,
11+
"application": False,
12+
"license": "AGPL-3",
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import hr_employee
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from odoo import api, fields, models
2+
3+
4+
class HrEmployee(models.Model):
5+
_inherit = "hr.employee"
6+
7+
@api.model_create_multi
8+
def create(self, vals_list):
9+
employees = super().create(vals_list)
10+
for employee in employees:
11+
employee._assign_accrual_plans_by_tags()
12+
return employees
13+
14+
def write(self, vals):
15+
res = super().write(vals)
16+
if "category_ids" in vals:
17+
for employee in self:
18+
employee._assign_accrual_plans_by_tags()
19+
return res
20+
21+
def _assign_accrual_plans_by_tags(self):
22+
self.ensure_one()
23+
employee_tag_names = self.category_ids.mapped("name")
24+
accrual_allocations = self.env["hr.leave.allocation"].search(
25+
[
26+
("employee_id", "=", False),
27+
("holiday_type", "=", "category"),
28+
("accrual_plan_id", "!=", False),
29+
]
30+
)
31+
32+
for allocation in accrual_allocations:
33+
existing_assignment = self.env["hr.leave.allocation"].search(
34+
[
35+
("employee_id", "=", self.id),
36+
("accrual_plan_id", "=", allocation.accrual_plan_id.id),
37+
("date_to", "=", False),
38+
],
39+
limit=1,
40+
)
41+
if (
42+
allocation.category_id.name in employee_tag_names
43+
and not existing_assignment
44+
):
45+
new_allocation = {
46+
"name": allocation.name,
47+
"holiday_type": "employee",
48+
"holiday_status_id": allocation.holiday_status_id.id,
49+
"notes": allocation.notes,
50+
"number_of_days": allocation.number_of_days,
51+
"parent_id": allocation.id,
52+
"employee_id": self.id,
53+
"employee_ids": [(6, 0, [self.id])],
54+
"state": "confirm",
55+
"allocation_type": allocation.allocation_type,
56+
"date_from": fields.Date.context_today(self),
57+
"accrual_plan_id": allocation.accrual_plan_id.id,
58+
}
59+
childs = allocation.with_context(
60+
mail_notify_force_send=False, mail_activity_automation_skip=True
61+
).create(new_allocation)
62+
childs.action_validate()
63+
elif (
64+
allocation.category_id.name not in employee_tag_names
65+
and existing_assignment
66+
):
67+
existing_assignment.date_to = fields.Date.context_today(self)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* `PyTech <https://pytech.it>`_:
2+
3+
* Quirino Leone <quirino.leone@pytech.it>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This module manages automatically accrual allocations by employee tags.
2+
When a new employee is created, accrual allocations are created starting from active accrual plans, based on its tags.
3+
Adding tags later and removing them is also managed.

0 commit comments

Comments
 (0)