Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions hr_holidays_accrual_by_tag/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

==========================
HR Holidays Accrual By Tag
==========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6a371341422010f0c2c1103e2663fc7bdd9fdd42bb6af0640786c2805713fc1c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr--holidays-lightgray.png?logo=github
:target: https://github.com/OCA/hr-holidays/tree/16.0/hr_holidays_accrual_by_tag
:alt: OCA/hr-holidays
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-holidays-16-0/hr-holidays-16-0-hr_holidays_accrual_by_tag
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module manages automatically accrual allocations by employee tags.
When a new employee is created, accrual allocations are created starting from active accrual plans, based on its tags.
Adding tags later and removing them is also managed.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-holidays/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`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**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* PyTech SRL

Contributors
~~~~~~~~~~~~

* `PyTech <https://pytech.it>`_:

* Quirino Leone <quirino.leone@pytech.it>
* Simone Rubino <simone.rubino@pytech.it>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

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.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions hr_holidays_accrual_by_tag/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions hr_holidays_accrual_by_tag/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "HR Holidays Accrual By Tag",
"version": "16.0.1.0.0",
"summary": "Automates accrual plan assignment based on employee tags.",
"category": "Human Resources",
"author": "PyTech SRL, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/hr-holidays",
"depends": ["hr", "hr_holidays"],
"data": [],
"installable": True,
"application": False,
"license": "AGPL-3",
}
1 change: 1 addition & 0 deletions hr_holidays_accrual_by_tag/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import hr_employee
79 changes: 79 additions & 0 deletions hr_holidays_accrual_by_tag/models/hr_employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from odoo import api, fields, models


class HrEmployee(models.Model):
_inherit = "hr.employee"

@api.model_create_multi
def create(self, vals_list):
employees = super().create(vals_list)
employees._assign_accrual_plans_by_tags()
return employees

def write(self, vals):
res = super().write(vals)
if "category_ids" in vals:
self._assign_accrual_plans_by_tags()
return res

def _assign_accrual_plans_by_tags(self):
accrual_allocations = self.env["hr.leave.allocation"].search(
[
("employee_id", "=", False),
("holiday_type", "=", "category"),
("accrual_plan_id", "!=", False),
]
)
existing_assignments = self.env["hr.leave.allocation"].search(
[
("employee_id", "in", self.ids),
("accrual_plan_id", "in", accrual_allocations.accrual_plan_id.ids),
("date_to", "=", False),
],
)

new_allocations_values = []
for employee in self:
employee_tags = employee.category_ids

for allocation in accrual_allocations:
employee_assignment = fields.first(
existing_assignments.filtered(
lambda assignment, allocation=allocation, employee=employee: (
assignment.accrual_plan_id == allocation.accrual_plan_id
and assignment.employee_id == employee
)
)
)
if allocation.category_id in employee_tags and not employee_assignment:
new_allocations_values.append(
{
"name": allocation.name,
"holiday_type": "employee",
"holiday_status_id": allocation.holiday_status_id.id,
"notes": allocation.notes,
"number_of_days": allocation.number_of_days,
"parent_id": allocation.id,
"employee_id": self.id,
"employee_ids": [(6, 0, [self.id])],
"state": "confirm",
"allocation_type": allocation.allocation_type,
"date_from": fields.Date.context_today(self),
"accrual_plan_id": allocation.accrual_plan_id.id,
}
)
elif (
allocation.category_id not in employee_tags and employee_assignment
):
employee_assignment.date_to = fields.Date.context_today(self)

if new_allocations_values:
new_allocations = (
self.env["hr.leave.allocation"]
.with_context(
mail_notify_force_send=False,
mail_activity_automation_skip=True,
)
.create(new_allocations_values)
)
new_allocations.action_validate()
4 changes: 4 additions & 0 deletions hr_holidays_accrual_by_tag/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `PyTech <https://pytech.it>`_:

* Quirino Leone <quirino.leone@pytech.it>
* Simone Rubino <simone.rubino@pytech.it>
3 changes: 3 additions & 0 deletions hr_holidays_accrual_by_tag/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module manages automatically accrual allocations by employee tags.
When a new employee is created, accrual allocations are created starting from active accrual plans, based on its tags.
Adding tags later and removing them is also managed.
Loading
Loading