Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][MIG] hr_employee_calendar_planning #1086

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e81b25f
[ADD] hr_employee_calendar_planning: Employee Calendar Planning
pedrobaeza Mar 12, 2019
7ac3f1d
[UPD] README.rst
OCA-git-bot Mar 14, 2019
ae14ffa
[MIG] hr_employee_calendar_planning
Mar 15, 2019
84c7733
[UPD] README.rst
OCA-git-bot May 15, 2019
3dd8b49
[12.0][MIG] hr_employee_calendar_planning
May 28, 2019
d229ebf
[UPD] Update hr_employee_calendar_planning.pot
oca-travis May 29, 2019
e576155
[12.0][IMP] hr_employee_calendar_planning
Jun 5, 2019
a33b2a0
[UPD] Update hr_employee_calendar_planning.pot
oca-travis Jun 5, 2019
95929a9
[IMP] hr_employee_calendar_planning: black, isort, prettier
May 6, 2020
e2b1553
[13.0][MIG] hr_employee_calendar_planning
May 6, 2020
1a2c82c
[13.0][IMP] support for two_week calendar
May 7, 2020
b633e66
[UPD] Update hr_employee_calendar_planning.pot
oca-travis May 8, 2020
504e9ba
[UPD] README.rst
OCA-git-bot May 8, 2020
b704617
Update translation files
oca-transbot May 8, 2020
0e63d0d
[FIX] hr_employee_calendar_planning: link leaves
chienandalu Nov 5, 2019
e7892c7
hr_employee_calendar_planning 13.0.1.0.1
OCA-git-bot Jun 17, 2020
f4f929b
[UPD] Eficent -> ForgeFlow
MiquelRForgeFlow Sep 30, 2020
4a33bfd
[UPD] README.rst
OCA-git-bot Sep 30, 2020
65ecd89
[14.0][MIG] hr_employee_calendar_planning
aphon61bank Nov 12, 2020
5e76cb1
[UPD] Update hr_employee_calendar_planning.pot
oca-travis May 9, 2021
818d611
[UPD] README.rst
OCA-git-bot May 9, 2021
627d987
Added translation using Weblate (French)
Yvesldff May 14, 2021
ccea68d
Translated using Weblate (French)
Yvesldff May 14, 2021
52de1e9
[FIX] hr_employee_calendar_planning: Prevent disable resource.calenda…
victoralmau Jul 13, 2021
9bda277
[UPD] Update hr_employee_calendar_planning.pot
oca-travis Jul 16, 2021
c11ebbb
hr_employee_calendar_planning 14.0.1.0.2
OCA-git-bot Jul 16, 2021
094aeca
Update translation files
oca-transbot Jul 16, 2021
ca04357
[FIX] hr_employee_calendar_planning: Add check_company to calendar_id…
victoralmau Jul 27, 2021
fa87ee8
[UPD] Update hr_employee_calendar_planning.pot
oca-travis Jul 28, 2021
f528d16
hr_employee_calendar_planning 14.0.1.1.0
OCA-git-bot Jul 28, 2021
da12074
Update translation files
oca-transbot Jul 28, 2021
a7f4f9b
[FIX] hr_employee_calendar_planning: Force to auto generate calendar …
victoralmau Sep 8, 2021
c686828
[UPD] Update hr_employee_calendar_planning.pot
oca-travis Sep 8, 2021
c909ae7
[UPD] README.rst
OCA-git-bot Sep 8, 2021
4b3b6df
Update translation files
oca-transbot Sep 8, 2021
27363b2
[FIX] hr_employee_calendar_planning: Regenerate automatic calendar 2 …
victoralmau Oct 15, 2021
ec604ff
[FIX] hr_employee_calendar_planning: Regenerate the automatic calenda…
victoralmau Oct 18, 2021
4135dd4
[UPD] README.rst
OCA-git-bot Feb 15, 2022
b9cba13
Translated using Weblate (Catalan)
Noel000 Mar 21, 2022
0add05f
[FIX] hr_employee_calendar_planning: Prevent inconsistent company + A…
victoralmau Apr 11, 2022
3f8014e
[UPD] Update hr_employee_calendar_planning.pot
Apr 25, 2022
2a58ec9
hr_employee_calendar_planning 14.0.1.3.1
OCA-git-bot Apr 25, 2022
6380242
Update translation files
oca-transbot Apr 25, 2022
6d15a19
[FIX] hr_employee_calendar_planning: Avoid error with parent
luistorresm Oct 26, 2021
859195c
hr_employee_calendar_planning 14.0.1.4.0
OCA-git-bot Apr 26, 2022
abb7a64
Added translation using Weblate (German)
marylla May 11, 2022
4c9ca07
[IMP] hr_employee_calendar_planning: black, isort, prettier
pegonzalezspesol Jul 7, 2022
2e89948
[MIG] hr_employee_calendar_planning: Migration to 15.0
pegonzalezspesol Jul 7, 2022
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
14 changes: 9 additions & 5 deletions hr_employee_calendar_planning/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Employee Calendar Planning
: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-lightgray.png?logo=github
:target: https://github.com/OCA/hr/tree/14.0/hr_employee_calendar_planning
:target: https://github.com/OCA/hr/tree/15.0/hr_employee_calendar_planning
:alt: OCA/hr
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-14-0/hr-14-0-hr_employee_calendar_planning
:target: https://translation.odoo-community.org/projects/hr-15-0/hr-15-0-hr_employee_calendar_planning
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/116/14.0
:target: https://runbot.odoo-community.org/runbot/116/15.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -74,7 +74,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_employee_calendar_planning%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_employee_calendar_planning%0Aversion:%2015.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.

Expand Down Expand Up @@ -104,6 +104,10 @@ Contributors

* Nattapong W. <[email protected]>

* `Pesol <https://www.pesol.es>`__:

* Pedro Evaristo Gonzalez Sanchez <[email protected]>

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

Expand All @@ -128,6 +132,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-victoralmau| |maintainer-pedrobaeza|

This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/14.0/hr_employee_calendar_planning>`_ project on GitHub.
This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/15.0/hr_employee_calendar_planning>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion hr_employee_calendar_planning/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Employee Calendar Planning",
"version": "14.0.1.4.0",
"version": "15.0.1.0.0",
"category": "Human Resources",
"website": "https://github.com/OCA/hr",
"author": "Tecnativa,Odoo Community Association (OCA)",
Expand Down
113 changes: 56 additions & 57 deletions hr_employee_calendar_planning/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,62 @@ def post_init_hook(cr, registry, employees=None):
"""Split current calendars by date ranges and assign new ones for
having proper initial data.
"""
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
if not employees:
employees = env["hr.employee"].search([])
calendars = employees.mapped("resource_calendar_id")
calendar_obj = env["resource.calendar"]
line_obj = env["resource.calendar.attendance"]
groups = line_obj.read_group(
[("calendar_id", "in", calendars.ids)],
["calendar_id", "date_from", "date_to"],
["calendar_id", "date_from:day", "date_to:day"],
lazy=False,
)
calendar_mapping = defaultdict(list)
for group in groups:
calendar = calendar_obj.browse(group["calendar_id"][0])
lines = line_obj.search(group["__domain"])
if len(calendar.attendance_ids) == len(lines):
# Don't alter calendar, as it's the same
new_calendar = calendar
else:
name = calendar.name + " {}-{}".format(
lines[0].date_from,
lines[0].date_to,
)
attendances = []
for line in lines:
data = line.copy_data({"date_from": False, "date_to": False})[0]
data.pop("calendar_id")
attendances.append((0, 0, data))
new_calendar = calendar_obj.create(
{"name": name, "attendance_ids": attendances}
)
calendar_mapping[calendar].append(
(lines[0].date_from, lines[0].date_to, new_calendar),
env = api.Environment(cr, SUPERUSER_ID, {})
if not employees:
employees = env["hr.employee"].search([])
calendars = employees.mapped("resource_calendar_id")
calendar_obj = env["resource.calendar"]
line_obj = env["resource.calendar.attendance"]
groups = line_obj.read_group(
[("calendar_id", "in", calendars.ids)],
["calendar_id", "date_from", "date_to"],
["calendar_id", "date_from:day", "date_to:day"],
lazy=False,
)
calendar_mapping = defaultdict(list)
for group in groups:
calendar = calendar_obj.browse(group["calendar_id"][0])
lines = line_obj.search(group["__domain"])
if len(calendar.attendance_ids) == len(lines):
# Don't alter calendar, as it's the same
new_calendar = calendar
else:
name = calendar.name + " {}-{}".format(
lines[0].date_from,
lines[0].date_to,
)
for employee in employees.filtered("resource_calendar_id"):
calendar_lines = []
for data in calendar_mapping[employee.resource_calendar_id]:
calendar_lines.append(
(
0,
0,
{
"date_start": data[0],
"date_end": data[1],
"calendar_id": data[2].id,
},
)
attendances = []
for line in lines:
data = line.copy_data({"date_from": False, "date_to": False})[0]
data.pop("calendar_id")
attendances.append((0, 0, data))
new_calendar = calendar_obj.create(
{"name": name, "attendance_ids": attendances}
)
calendar_mapping[calendar].append(
(lines[0].date_from, lines[0].date_to, new_calendar),
)
for employee in employees.filtered("resource_calendar_id"):
calendar_lines = []
for data in calendar_mapping[employee.resource_calendar_id]:
calendar_lines.append(
(
0,
0,
{
"date_start": data[0],
"date_end": data[1],
"calendar_id": data[2].id,
},
)
# Extract employee's existing leaves so they are passed to the new
# automatic calendar.
leaves = employee.resource_calendar_id.leave_ids.filtered(
lambda x: x.resource_id == employee.resource_id
)
employee.calendar_ids = calendar_lines
employee.resource_calendar_id.active = False
# Now the automatic calendar has been created, so we link the
# leaves to that one so they count correctly.
leaves.write({"calendar_id": employee.resource_calendar_id.id})
# Extract employee's existing leaves so they are passed to the new
# automatic calendar.
leaves = employee.resource_calendar_id.leave_ids.filtered(
lambda x: x.resource_id == employee.resource_id
)
employee.calendar_ids = calendar_lines
employee.resource_calendar_id.active = False
# Now the automatic calendar has been created, so we link the
# leaves to that one so they count correctly.
leaves.write({"calendar_id": employee.resource_calendar_id.id})

This file was deleted.

This file was deleted.

16 changes: 12 additions & 4 deletions hr_employee_calendar_planning/models/resource_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ def _check_active(self):
)
if total_items:
raise ValidationError(
_("%s is used in %s employee(s). You should change them first.")
% (item.name, total_items)
_(
"%(item_name)s is used in %(total_items)s employee(s)."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update at least Spanish translation?

"You should change them first.",
item_name=item.name,
total_items=total_items,
)
)

@api.constrains("company_id")
Expand All @@ -36,8 +40,12 @@ def _check_company_id(self):
)
if total_items:
raise ValidationError(
_("%s is used in %s employee(s) related to another company.")
% (item.name, total_items)
_(
"%(item_name)s is used in %(total_items)s employee(s)"
" related to another company.",
item_name=item.name,
total_items=total_items,
)
)

def write(self, vals):
Expand Down
4 changes: 4 additions & 0 deletions hr_employee_calendar_planning/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
* Jordi Ballester Alomar ([email protected])

* Nattapong W. <[email protected]>

* `Pesol <https://www.pesol.es>`__:

* Pedro Evaristo Gonzalez Sanchez <[email protected]>
12 changes: 8 additions & 4 deletions hr_employee_calendar_planning/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Employee Calendar Planning</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Employee Calendar Planning</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/hr/tree/14.0/hr_employee_calendar_planning"><img alt="OCA/hr" src="https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/hr-14-0/hr-14-0-hr_employee_calendar_planning"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/116/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/hr/tree/15.0/hr_employee_calendar_planning"><img alt="OCA/hr" src="https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/hr-15-0/hr-15-0-hr_employee_calendar_planning"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/116/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module allows to manage employee working time with profiles by date
intervals.</p>
<p>The profiles are regular working time calendars, but they are treated as
Expand Down Expand Up @@ -424,7 +424,7 @@ <h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/hr/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/hr/issues/new?body=module:%20hr_employee_calendar_planning%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/hr/issues/new?body=module:%20hr_employee_calendar_planning%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -452,6 +452,10 @@ <h2><a class="toc-backref" href="#id7">Contributors</a></h2>
<li>Nattapong W. &lt;<a class="reference external" href="mailto:aphon61bank&#64;gmail.com">aphon61bank&#64;gmail.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://www.pesol.es">Pesol</a>:<ul>
<li>Pedro Evaristo Gonzalez Sanchez &lt;<a class="reference external" href="mailto:pedro.gonzalez&#64;pesol.es">pedro.gonzalez&#64;pesol.es</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -463,7 +467,7 @@ <h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external" href="https://github.com/victoralmau"><img alt="victoralmau" src="https://github.com/victoralmau.png?size=40px" /></a> <a class="reference external" href="https://github.com/pedrobaeza"><img alt="pedrobaeza" src="https://github.com/pedrobaeza.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr/tree/14.0/hr_employee_calendar_planning">OCA/hr</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr/tree/15.0/hr_employee_calendar_planning">OCA/hr</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from ..hooks import post_init_hook


class TestHrEmployeeCalendarPlanning(common.SavepointCase):
class TestHrEmployeeCalendarPlanning(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
super(TestHrEmployeeCalendarPlanning, cls).setUpClass()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need of this diff. It was OK before

resource_calendar = cls.env["resource.calendar"]
cls.calendar1 = resource_calendar.create(
{"name": "Test calendar 1", "attendance_ids": []}
Expand Down
5 changes: 4 additions & 1 deletion hr_employee_calendar_planning/views/hr_employee_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<attribute name="invisible">1</attribute>
</field>
<field name="resource_calendar_id" position="after">
<field name="calendar_ids" context="{'default_company_id': company_id}">
<field
name="calendar_ids"
context="{'default_company_id': parent.company_id}"
>
<tree editable="top">
<field name="company_id" invisible="1" />
<field name="date_start" />
Expand Down