-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
22 changed files
with
1,792 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,78 @@ | ||
================ | ||
Employees Shifts | ||
================ | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:267f057335dc26361bc24fcc7b9ad4f01ba39496cccb443c54a519cc725c3524 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/licence-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%2Fshift--planning-lightgray.png?logo=github | ||
:target: https://github.com/OCA/shift-planning/tree/14.0/hr_shift | ||
:alt: OCA/shift-planning | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/shift-planning-14-0/shift-planning-14-0-hr_shift | ||
: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/shift-planning&target_branch=14.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
Assign shifts to employees. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/shift-planning/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/shift-planning/issues/new?body=module:%20hr_shift%0Aversion:%2014.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 | ||
------- | ||
|
||
* Tecnativa | ||
|
||
Contributors | ||
------------ | ||
|
||
- `Tecnativa <https://tecnativa.com>`__: | ||
|
||
- David Vidal | ||
|
||
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/shift-planning <https://github.com/OCA/shift-planning/tree/14.0/hr_shift>`_ 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,19 @@ | ||
# Copyright 2024 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
{ | ||
"name": "Employees Shifts", | ||
"summary": "Define shifts for employees", | ||
"version": "14.0.1.0.0", | ||
"author": "Tecnativa, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"website": "https://github.com/OCA/shift-planning", | ||
"category": "Marketing", | ||
"depends": ["hr_holidays_public", "base_sparse_field"], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/shift_planning_views.xml", | ||
"views/shift_template_views.xml", | ||
"views/res_config_settings_views.xml", | ||
"views/assets.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,6 @@ | ||
from . import res_company | ||
from . import resource_calendar | ||
from . import res_config_settings | ||
from . import shift_planning | ||
from . import shift_template | ||
from . import hr_employee |
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,42 @@ | ||
# Copyright 2024 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo import fields, models | ||
|
||
|
||
class HrEmployeeBase(models.AbstractModel): | ||
_inherit = "hr.employee.base" | ||
|
||
current_shift_id = fields.Many2one( | ||
comodel_name="hr.shift.planning.line", compute="_compute_current_shift_id" | ||
) | ||
|
||
def _shift_of_date(self, min_time, max_time): | ||
return ( | ||
self.env["hr.shift.planning.line"] | ||
.sudo() | ||
.search( | ||
[ | ||
("employee_id", "=", self.id), | ||
("state", "=", "assigned"), | ||
("start_time", ">=", min_time), | ||
("end_time", "<=", max_time), | ||
] | ||
) | ||
) | ||
|
||
def _compute_current_shift_id(self): | ||
"""Current shift for a given employee if any""" | ||
today = fields.Date.today() | ||
now = fields.Datetime.now() | ||
min_time = fields.datetime.combine(today, now.min.time()) | ||
max_time = fields.datetime.combine(today, now.max.time()) | ||
for employee in self: | ||
employee.current_shift_id = employee._shift_of_date(min_time, max_time) | ||
|
||
def _get_employee_working_now(self): | ||
# Get shift info if available | ||
employees_in_current_shift = self.filtered("current_shift_id") | ||
others = super( | ||
HrEmployeeBase, (self - employees_in_current_shift) | ||
)._get_employee_working_now() | ||
return others + employees_in_current_shift.ids | ||
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,13 @@ | ||
# Copyright 2024 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo import fields, models | ||
|
||
from .shift_template import WEEK_DAYS_SELECTION | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
# Default from monday to friday | ||
shift_start_day = fields.Selection(selection=WEEK_DAYS_SELECTION, default="0") | ||
shift_end_day = fields.Selection(selection=WEEK_DAYS_SELECTION, default="4") |
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,12 @@ | ||
# Copyright 2024 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
shift_start_day = fields.Selection( | ||
related="company_id.shift_start_day", readonly=False | ||
) | ||
shift_end_day = fields.Selection(related="company_id.shift_end_day", readonly=False) |
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,57 @@ | ||
# Copyright 2024 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from datetime import datetime | ||
|
||
from odoo import api, models | ||
from odoo.tools import groupby | ||
|
||
|
||
class ResourceCalendar(models.Model): | ||
_inherit = "resource.calendar" | ||
|
||
@api.model | ||
def _resource_shift_for_datetime_range(self, start_dt, end_dt, resources, tz=None): | ||
min_time = datetime.combine(start_dt, start_dt.min.time()) | ||
max_time = datetime.combine(end_dt, end_dt.max.time()) | ||
shifts = self.env["hr.shift.planning.line"].search( | ||
[ | ||
("resource_id", "in", resources.ids), | ||
("state", "=", "assigned"), | ||
("start_time", ">=", min_time), | ||
("end_time", "<=", max_time), | ||
] | ||
) | ||
return shifts | ||
|
||
def _attendance_intervals_batch( | ||
self, start_dt, end_dt, resources=None, domain=None, tz=None | ||
): | ||
# Override calendar intervals when a shift is found and substitute those | ||
# intervals with the ones on the shift | ||
# TODO: deal with TZ! | ||
res = super()._attendance_intervals_batch( | ||
start_dt, end_dt, resources, domain, tz | ||
) | ||
if resources: | ||
shift_ids = self._resource_shift_for_datetime_range( | ||
start_dt, end_dt, resources, tz=tz | ||
) | ||
for resource, shifts in groupby(shift_ids, lambda x: x.resource_id): | ||
intervals_to_add = [] | ||
intervals_to_remove = [] | ||
resource_intervals = res[resource.id]._items | ||
for shift in shifts: | ||
intervals_to_remove += [ | ||
(start, end, resource_item) | ||
for start, end, resource_item in resource_intervals | ||
if ( | ||
shift.start_time | ||
>= datetime.combine(start, start.min.time()) | ||
and shift.end_time >= datetime.combine(end, end.min.time()) | ||
) | ||
] | ||
intervals_to_add.append((shift.start_time, shift.end_time, shift)) | ||
res[resource.id]._items = [ | ||
x for x in resource_intervals if x not in intervals_to_remove | ||
] + intervals_to_add | ||
return res | ||
Oops, something went wrong.