-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] resource_calendar_leaves_province
- Loading branch information
Showing
19 changed files
with
968 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
========================== | ||
Resource Leaves Geographic | ||
========================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:e5409e484959f22489b0c0976ce8231c697b28572e9d29285501c0e20bc49179 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Alpha | ||
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-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/resource_leaves_geographic | ||
: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-resource_leaves_geographic | ||
: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 extends the functionality of Public Holidays to support | ||
States and allow you to define Local Holidays more easily in the Company | ||
Calendar. | ||
|
||
Shows on Time Off all the holidays (with/without State) in the Public | ||
Holidays section. Only Public Holidays without State will be with grey | ||
background. | ||
|
||
Shows on Time Off > Overview all the holidays (with/without State) with | ||
the proper grey background for each employee. | ||
|
||
This module is compatible with Attendances and Contracts (but those | ||
modules are not required). | ||
|
||
.. IMPORTANT:: | ||
This is an alpha version, the data model and design can change at any time without warning. | ||
Only for development or testing purpose, do not use in production. | ||
`More details on development status <https://odoo-community.org/page/development-status>`_ | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Use Cases / Context | ||
=================== | ||
|
||
This module was developed because in order to differentiate local | ||
Employee holidays, they must be added to their calendars instead of | ||
being able to mark them on the general company calendar. | ||
|
||
This will be useful for you if you want to be able to create holidays by | ||
State in the company calendar and have them automatically applied to all | ||
employees based on their workplace. | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
1. Go to Time Off app > Configuration > Public Holidays | ||
2. Create a Public Holiday without State with name *Local Holiday* | ||
3. Create an *Employee 1* and set his Work Address in the same State | ||
than your *Local Holiday* | ||
4. Create an *Employee 2* and set his Work Address in other State than | ||
your *Local Holiday* | ||
5. Go to Time Off > Overview and check the grey background is only on | ||
*Employee 1* on the days used in *Local Holiday* | ||
6. Create a Time Off for *Employee 1* that involves *Local Holiday* and | ||
check the days used are computed correctly | ||
7. Create a Time Off for *Employee 2* that involves *Local Holiday* and | ||
check the days used are computed correctly (more days than the Time | ||
Off of *Employee 1*) | ||
|
||
If you have installed Attendances and Contracts apps, and create | ||
attenances for both employees on the *Local Holiday* you can also check | ||
Extra Hours are computed correctly in both employees. | ||
|
||
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:%20resource_leaves_geographic%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 | ||
------- | ||
|
||
* Moduon | ||
|
||
Contributors | ||
------------ | ||
|
||
- Eduardo de Miguel (`Moduon <https://www.moduon.team/>`__) | ||
|
||
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. | ||
|
||
.. |maintainer-Shide| image:: https://github.com/Shide.png?size=40px | ||
:target: https://github.com/Shide | ||
:alt: Shide | ||
.. |maintainer-rafaelbn| image:: https://github.com/rafaelbn.png?size=40px | ||
:target: https://github.com/rafaelbn | ||
:alt: rafaelbn | ||
|
||
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-Shide| |maintainer-rafaelbn| | ||
|
||
This module is part of the `OCA/hr-holidays <https://github.com/OCA/hr-holidays/tree/16.0/resource_leaves_geographic>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2024 Moduon Team S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) | ||
|
||
{ | ||
"name": "Resource Leaves Geographic", | ||
"summary": "Add geographic State to Resource Calendar Leaves", | ||
"version": "16.0.1.0.0", | ||
"development_status": "Alpha", | ||
"category": "Human Resources/Time Off", | ||
"website": "https://github.com/OCA/hr-holidays", | ||
"author": "Moduon, Odoo Community Association (OCA)", | ||
"maintainers": ["Shide", "rafaelbn"], | ||
"license": "LGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": [ | ||
"resource", | ||
"hr_holidays", | ||
], | ||
"data": [ | ||
"views/resource_calendar_leaves_views.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * resource_leaves_geographic | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-07-31 07:50+0000\n" | ||
"PO-Revision-Date: 2024-07-31 09:52+0200\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"Language: es\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
"X-Generator: Poedit 3.4.4\n" | ||
|
||
#. module: resource_leaves_geographic | ||
#: model:ir.model,name:resource_leaves_geographic.model_resource_calendar_leaves | ||
msgid "Resource Time Off Detail" | ||
msgstr "Detalle de las ausencias del recurso" | ||
|
||
#. module: resource_leaves_geographic | ||
#: model:ir.model,name:resource_leaves_geographic.model_resource_calendar | ||
msgid "Resource Working Time" | ||
msgstr "Tiempo de Trabajo de Recursos" | ||
|
||
#. module: resource_leaves_geographic | ||
#: model:ir.model.fields,field_description:resource_leaves_geographic.field_resource_calendar_leaves__state_ids | ||
msgid "States" | ||
msgstr "Estados" | ||
|
||
#. module: resource_leaves_geographic | ||
#: model:ir.model.fields,help:resource_leaves_geographic.field_resource_calendar_leaves__state_ids | ||
msgid "States for which this leave is applicable" | ||
msgstr "Estados para los que se aplica esta ausencia" |
36 changes: 36 additions & 0 deletions
36
resource_leaves_geographic/i18n/resource_leaves_geographic.pot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * resource_leaves_geographic | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-07-31 07:50+0000\n" | ||
"PO-Revision-Date: 2024-07-31 07:50+0000\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: resource_leaves_geographic | ||
#: model:ir.model,name:resource_leaves_geographic.model_resource_calendar_leaves | ||
msgid "Resource Time Off Detail" | ||
msgstr "" | ||
|
||
#. module: resource_leaves_geographic | ||
#: model:ir.model,name:resource_leaves_geographic.model_resource_calendar | ||
msgid "Resource Working Time" | ||
msgstr "" | ||
|
||
#. module: resource_leaves_geographic | ||
#: model:ir.model.fields,field_description:resource_leaves_geographic.field_resource_calendar_leaves__state_ids | ||
msgid "States" | ||
msgstr "" | ||
|
||
#. module: resource_leaves_geographic | ||
#: model:ir.model.fields,help:resource_leaves_geographic.field_resource_calendar_leaves__state_ids | ||
msgid "States for which this leave is applicable" | ||
msgstr "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import resource_calendar_leaves | ||
from . import resource_calendar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Copyright 2024 Moduon Team S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) | ||
|
||
from collections import defaultdict | ||
|
||
from odoo import models | ||
|
||
from odoo.addons.resource.models.resource import Intervals, make_aware | ||
|
||
|
||
class ResourceCalendar(models.Model): | ||
_inherit = "resource.calendar" | ||
|
||
def _get_general_time_off_intervals_by_state(self, domain=None, any_calendar=False): | ||
"""Get a map of State to Intervals of leaves for the given domain.""" | ||
domain = domain or [] | ||
# Respect the any_calendar option | ||
if not any_calendar: | ||
domain += [("calendar_id", "in", self.ids + [False])] | ||
# Ensure that the leaves are not related to a specific resource | ||
domain += [ | ||
("resource_id", "=", False), | ||
] | ||
# Iterate all matching leaves | ||
state_interval_map = defaultdict(Intervals) | ||
for res_cal_leave in self.env["resource.calendar.leaves"].search(domain): | ||
dttf, _f = make_aware(res_cal_leave.date_from) | ||
dttt, _f = make_aware(res_cal_leave.date_to) | ||
# Add the interval to the corresponding State or False if no state | ||
if res_cal_leave.state_ids: | ||
for state in res_cal_leave.state_ids: | ||
state_interval_map[state.id] |= Intervals( | ||
[(dttf, dttt, res_cal_leave)] | ||
) | ||
else: | ||
state_interval_map[False] |= Intervals([(dttf, dttt, res_cal_leave)]) | ||
return state_interval_map | ||
|
||
def _leave_intervals_batch( | ||
self, start_dt, end_dt, resources=None, domain=None, tz=None, any_calendar=False | ||
): | ||
# All interval batches (with/out State) | ||
res = super()._leave_intervals_batch( | ||
start_dt, | ||
end_dt, | ||
resources=resources, | ||
domain=domain, | ||
tz=tz, | ||
any_calendar=any_calendar, | ||
) | ||
# Overwrite the result if resources are specified, but only with | ||
# the global leaves (skipping the local leaves) using the domain | ||
for resource in resources or []: | ||
res.update( | ||
super()._leave_intervals_batch( | ||
start_dt, | ||
end_dt, | ||
resources=resource, | ||
domain=[("state_ids", "=", False)], # Force global leaves | ||
tz=tz, | ||
any_calendar=any_calendar, | ||
) | ||
) | ||
# Get Local interval batches by State | ||
state_interval_map = self._get_general_time_off_intervals_by_state( | ||
domain=domain, any_calendar=any_calendar | ||
) | ||
# Post-process generated intervals | ||
for resource_id in res.keys(): | ||
if not resource_id: | ||
# If no resource is specified, only consider Global leaves | ||
res[resource_id] = state_interval_map[False] | ||
else: | ||
# If resource is specified, add Local Leaves to the result if | ||
# the State of its Work Address has Local leaves | ||
resource_state_id = ( | ||
self.env["hr.employee"] | ||
.sudo() | ||
.search([("resource_id", "=", resource_id)], limit=1) | ||
.address_id.state_id.id | ||
) | ||
if resource_state_id in state_interval_map: | ||
res[resource_id] |= state_interval_map[resource_state_id] | ||
return res |
14 changes: 14 additions & 0 deletions
14
resource_leaves_geographic/models/resource_calendar_leaves.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2024 Moduon Team S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResourceCalendarLeaves(models.Model): | ||
_inherit = "resource.calendar.leaves" | ||
|
||
state_ids = fields.Many2many( | ||
comodel_name="res.country.state", | ||
string="States", | ||
help="States for which this leave is applicable", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This module was developed because in order to differentiate local Employee holidays, they must be added to their calendars instead of being able to mark them on the general company calendar. | ||
|
||
This will be useful for you if you want to be able to create holidays by State in the company calendar and have them automatically applied to all employees based on their workplace. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Eduardo de Miguel ([Moduon](https://www.moduon.team/)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This module extends the functionality of Public Holidays to support States and allow you to define Local Holidays more easily in the Company Calendar. | ||
|
||
Shows on Time Off all the holidays (with/without State) in the Public Holidays section. Only Public Holidays without State will be with grey background. | ||
|
||
Shows on Time Off > Overview all the holidays (with/without State) with the proper grey background for each employee. | ||
|
||
This module is compatible with Attendances and Contracts (but those modules are not required). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
To use this module, you need to: | ||
|
||
1. Go to Time Off app > Configuration > Public Holidays | ||
2. Create a Public Holiday without State with name *Local Holiday* | ||
3. Create an *Employee 1* and set his Work Address in the same State than your *Local Holiday* | ||
4. Create an *Employee 2* and set his Work Address in other State than your *Local Holiday* | ||
5. Go to Time Off > Overview and check the grey background is only on *Employee 1* on the days used in *Local Holiday* | ||
6. Create a Time Off for *Employee 1* that involves *Local Holiday* and check the days used are computed correctly | ||
7. Create a Time Off for *Employee 2* that involves *Local Holiday* and check the days used are computed correctly (more days than the Time Off of *Employee 1*) | ||
|
||
If you have installed Attendances and Contracts apps, and create attenances for both employees on the *Local Holiday* you can also check Extra Hours are computed correctly in both employees. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.