diff --git a/hr_employee_calendar_planning/README.rst b/hr_employee_calendar_planning/README.rst index 1f16d57a510..1c9fec23858 100644 --- a/hr_employee_calendar_planning/README.rst +++ b/hr_employee_calendar_planning/README.rst @@ -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| @@ -52,7 +52,7 @@ Configuration #. Go to *Employees > Employees*. #. Open or create a new one. -#. On the "Work Information" tab, fill the section "Calendar planning" with: +#. On the "Work Information" tab, fill the section "Working Hours" with: * Starting date (optional). * Ending date (optional). @@ -74,7 +74,7 @@ Bug Tracker Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -104,6 +104,10 @@ Contributors * Nattapong W. +* `Pesol `__: + + * Pedro Evaristo Gonzalez Sanchez + Maintainers ~~~~~~~~~~~ @@ -128,6 +132,6 @@ Current `maintainers `__: |maintainer-victoralmau| |maintainer-pedrobaeza| -This module is part of the `OCA/hr `_ project on GitHub. +This module is part of the `OCA/hr `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_employee_calendar_planning/__manifest__.py b/hr_employee_calendar_planning/__manifest__.py index 302bda6022a..96b845874fd 100644 --- a/hr_employee_calendar_planning/__manifest__.py +++ b/hr_employee_calendar_planning/__manifest__.py @@ -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.1", + "version": "15.0.1.0.0", "category": "Human Resources", "website": "https://github.com/OCA/hr", "author": "Tecnativa,Odoo Community Association (OCA)", diff --git a/hr_employee_calendar_planning/hooks.py b/hr_employee_calendar_planning/hooks.py index 3a945525770..4aa879a2862 100644 --- a/hr_employee_calendar_planning/hooks.py +++ b/hr_employee_calendar_planning/hooks.py @@ -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}) diff --git a/hr_employee_calendar_planning/i18n/es.po b/hr_employee_calendar_planning/i18n/es.po index 5fa77734494..1be5893a139 100644 --- a/hr_employee_calendar_planning/i18n/es.po +++ b/hr_employee_calendar_planning/i18n/es.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 12.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-04-11 14:49+0000\n" -"PO-Revision-Date: 2022-04-11 16:50+0200\n" +"POT-Creation-Date: 2022-08-29 06:53+0000\n" +"PO-Revision-Date: 2022-08-29 08:55+0200\n" "Last-Translator: Carles Antoli \n" "Language-Team: none\n" "Language: es\n" @@ -15,19 +15,27 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Poedit 2.3\n" +"X-Generator: Poedit 3.0.1\n" #. module: hr_employee_calendar_planning #: code:addons/hr_employee_calendar_planning/models/resource_calendar.py:0 #, python-format -msgid "%s is used in %s employee(s) related to another company." -msgstr "%s está usado con el empleado(s) %s relacionado con otra compañía." +msgid "" +"%(item_name)s is used in %(total_items)s employee(s) related to another " +"company." +msgstr "" +"%(item_name)s está usado en %(total_items)s empleado/a(s) relacionado/a(s) con " +"otra compañía." #. module: hr_employee_calendar_planning #: code:addons/hr_employee_calendar_planning/models/resource_calendar.py:0 #, python-format -msgid "%s is used in %s employee(s). You should change them first." -msgstr "%s está usado con el empleado(s) %s . Deberías cambiarlo primero." +msgid "" +"%(item_name)s is used in %(total_items)s employee(s).You should change them " +"first." +msgstr "" +"%(item_name)s está usado en %(total_items)s empleado(s). Debería cambiarlo " +"primero." #. module: hr_employee_calendar_planning #: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_resource_calendar__active @@ -71,9 +79,7 @@ msgid "Date end should be higher than date start" msgstr "La fecha de fin debe ser mayor que la de inicio" #. module: hr_employee_calendar_planning -#: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_hr_employee__display_name #: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_hr_employee_calendar__display_name -#: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_resource_calendar__display_name msgid "Display Name" msgstr "Nombre a mostrar" @@ -94,9 +100,7 @@ msgid "End Date" msgstr "Fecha de finalización" #. module: hr_employee_calendar_planning -#: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_hr_employee__id #: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_hr_employee_calendar__id -#: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_resource_calendar__id msgid "ID" msgstr "ID" @@ -110,9 +114,7 @@ msgstr "" "trabajo sin eliminarlo." #. module: hr_employee_calendar_planning -#: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_hr_employee____last_update #: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_hr_employee_calendar____last_update -#: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_resource_calendar____last_update msgid "Last Modified on" msgstr "Última modificación el" diff --git a/hr_employee_calendar_planning/i18n/hr_employee_calendar_planning.pot b/hr_employee_calendar_planning/i18n/hr_employee_calendar_planning.pot index defa8f7a669..0430d958464 100644 --- a/hr_employee_calendar_planning/i18n/hr_employee_calendar_planning.pot +++ b/hr_employee_calendar_planning/i18n/hr_employee_calendar_planning.pot @@ -4,8 +4,10 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 14.0\n" +"Project-Id-Version: Odoo Server 15.0\n" "Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-08-29 06:53+0000\n" +"PO-Revision-Date: 2022-08-29 06:53+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -16,13 +18,17 @@ msgstr "" #. module: hr_employee_calendar_planning #: code:addons/hr_employee_calendar_planning/models/resource_calendar.py:0 #, python-format -msgid "%s is used in %s employee(s) related to another company." +msgid "" +"%(item_name)s is used in %(total_items)s employee(s) related to another " +"company." msgstr "" #. module: hr_employee_calendar_planning #: code:addons/hr_employee_calendar_planning/models/resource_calendar.py:0 #, python-format -msgid "%s is used in %s employee(s). You should change them first." +msgid "" +"%(item_name)s is used in %(total_items)s employee(s).You should change them " +"first." msgstr "" #. module: hr_employee_calendar_planning @@ -67,9 +73,7 @@ msgid "Date end should be higher than date start" msgstr "" #. module: hr_employee_calendar_planning -#: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_hr_employee__display_name #: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_hr_employee_calendar__display_name -#: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_resource_calendar__display_name msgid "Display Name" msgstr "" @@ -90,9 +94,7 @@ msgid "End Date" msgstr "" #. module: hr_employee_calendar_planning -#: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_hr_employee__id #: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_hr_employee_calendar__id -#: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_resource_calendar__id msgid "ID" msgstr "" @@ -104,9 +106,7 @@ msgid "" msgstr "" #. module: hr_employee_calendar_planning -#: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_hr_employee____last_update #: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_hr_employee_calendar____last_update -#: model:ir.model.fields,field_description:hr_employee_calendar_planning.field_resource_calendar____last_update msgid "Last Modified on" msgstr "" diff --git a/hr_employee_calendar_planning/migrations/14.0.1.2.0/post-migration.py b/hr_employee_calendar_planning/migrations/14.0.1.2.0/post-migration.py deleted file mode 100644 index 6a83c0dbf7b..00000000000 --- a/hr_employee_calendar_planning/migrations/14.0.1.2.0/post-migration.py +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2021 Tecnativa - Víctor Martínez -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, version): - if version >= "14.0.1.0.0": - openupgrade.logged_query( - env.cr, - """ - UPDATE resource_calendar - SET auto_generate = true - WHERE active = false""", - ) diff --git a/hr_employee_calendar_planning/migrations/14.0.1.3.0/post-migration.py b/hr_employee_calendar_planning/migrations/14.0.1.3.0/post-migration.py deleted file mode 100644 index 3319feab202..00000000000 --- a/hr_employee_calendar_planning/migrations/14.0.1.3.0/post-migration.py +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright 2021 Tecnativa - Víctor Martínez -# Copyright 2021 Tecnativa - Pedro M. Baeza -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, version): - env["hr.employee"].with_context(active_test=False).search([]).filtered( - lambda x: any(c.calendar_id.two_weeks_calendar for c in x.calendar_ids) - and any(not c.calendar_id.two_weeks_calendar for c in x.calendar_ids) - ).regenerate_calendar() diff --git a/hr_employee_calendar_planning/models/resource_calendar.py b/hr_employee_calendar_planning/models/resource_calendar.py index a9faeb80a79..4e8ae193515 100644 --- a/hr_employee_calendar_planning/models/resource_calendar.py +++ b/hr_employee_calendar_planning/models/resource_calendar.py @@ -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)." + "You should change them first.", + item_name=item.name, + total_items=total_items, + ) ) @api.constrains("company_id") @@ -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): diff --git a/hr_employee_calendar_planning/readme/CONFIGURE.rst b/hr_employee_calendar_planning/readme/CONFIGURE.rst index c9781df1220..8668fcbb774 100644 --- a/hr_employee_calendar_planning/readme/CONFIGURE.rst +++ b/hr_employee_calendar_planning/readme/CONFIGURE.rst @@ -1,6 +1,6 @@ #. Go to *Employees > Employees*. #. Open or create a new one. -#. On the "Work Information" tab, fill the section "Calendar planning" with: +#. On the "Work Information" tab, fill the section "Working Hours" with: * Starting date (optional). * Ending date (optional). diff --git a/hr_employee_calendar_planning/readme/CONTRIBUTORS.rst b/hr_employee_calendar_planning/readme/CONTRIBUTORS.rst index e689dd96da3..f58a7bfe7e8 100644 --- a/hr_employee_calendar_planning/readme/CONTRIBUTORS.rst +++ b/hr_employee_calendar_planning/readme/CONTRIBUTORS.rst @@ -12,3 +12,7 @@ * Jordi Ballester Alomar (jordi.ballester@forgeflow.com) * Nattapong W. + +* `Pesol `__: + + * Pedro Evaristo Gonzalez Sanchez diff --git a/hr_employee_calendar_planning/static/description/index.html b/hr_employee_calendar_planning/static/description/index.html index fbbaa2f7f64..62863170c8c 100644 --- a/hr_employee_calendar_planning/static/description/index.html +++ b/hr_employee_calendar_planning/static/description/index.html @@ -3,7 +3,7 @@ - + Employee Calendar Planning