From 33dd30872909e526dae09305828df9a6dadd9c5e Mon Sep 17 00:00:00 2001 From: Michael Telahun Makonnen Date: Sat, 22 Nov 2025 13:53:33 +0300 Subject: [PATCH 1/2] hr_data_import: allow updating imported employee records' 'rest day' value --- .../models/hr_data_import_employee.py | 64 ++++++++++++++++++- hr_data_import/tests/test_import.py | 26 ++++++++ .../views/hr_data_import_employee_views.xml | 19 ++++++ resource_schedule/README.rst | 18 ++---- .../static/description/index.html | 32 ++++------ 5 files changed, 127 insertions(+), 32 deletions(-) diff --git a/hr_data_import/models/hr_data_import_employee.py b/hr_data_import/models/hr_data_import_employee.py index b622995d..0361bc42 100644 --- a/hr_data_import/models/hr_data_import_employee.py +++ b/hr_data_import/models/hr_data_import_employee.py @@ -84,7 +84,10 @@ class ImportEmployee(models.Model): comodel_name="hr.policy.group", ) related_employee_id = fields.Many2one("hr.employee") - state = fields.Selection([("new", "New"), ("imported", "Imported")], default="new") + state = fields.Selection( + [("new", "New"), ("imported", "Imported"), ("updated", "Updated")], + default="new", + ) company_id = fields.Many2one("res.company", default=lambda s: s.env.company) currency_id = fields.Many2one( string="Currency", related="company_id.currency_id", readonly=True @@ -94,6 +97,18 @@ class ImportEmployee(models.Model): anlv_used = fields.Float("Used", digits=DA_LEAVE, default=0.00) anlv_remain = fields.Float("Remaining", digits=DA_LEAVE, default=0.00) anlv_date = fields.Date("As of") + rest_day = fields.Selection( + selection=[ + ("Monday", "Monday"), + ("Tuesday", "Tuesday"), + ("Wednesday", "Wednesday"), + ("Thursday", "Thursday"), + ("Friday", "Friday"), + ("Saturday", "Saturday"), + ("Sunday", "Sunday"), + ("out", False) + ] + ) def action_import_employees(self): if self.filtered(lambda so: so.state != "new"): @@ -101,11 +116,14 @@ def action_import_employees(self): self.import_records() self.write({"state": "imported"}) + def action_update_employees(self): + self.update_records() + self.write({"state": "updated"}) + def import_records(self): partner_obj = self.env["res.partner"] - # Create the basic hr.employee record values_list = [] for rec in self: # Create contact @@ -119,6 +137,8 @@ def import_records(self): "vat": (rec.taxid) and rec.taxid or False, } ) + + # Create the basic hr.employee record val = { "name": rec.name, "import_data_id": rec.id, @@ -165,6 +185,18 @@ def import_records(self): # Additional changes to system self.create_contracts(employees) self.create_annual_leave_allocation(employees) + self.set_rest_day(employees) + + return employees + + def update_records(self): + + employees = self.env["hr.employee"].search( + ["id", "in", self.mapped("related_employee_id.id")] + ) + + # Additional changes to system + self.set_rest_day(employees) return employees @@ -244,3 +276,31 @@ def get_leave_days_accrued(self, employee, hire_date): accrued_todate += (delta.days / 30) * monthly_accrual return accrued_todate + + def set_rest_day(self, employees): + + mon = self.env.ref("resource_schedule.wd_mon") + tue = self.env.ref("resource_schedule.wd_tue") + wed = self.env.ref("resource_schedule.wd_wed") + thu = self.env.ref("resource_schedule.wd_thu") + fri = self.env.ref("resource_schedule.wd_fri") + sat = self.env.ref("resource_schedule.wd_sat") + sun = self.env.ref("resource_schedule.wd_sun") + + for ee in employees: + resource = ee.resource_id + data_id = self.filtered(lambda s, ee=ee: s.related_employee_id.id == ee.id) + if data_id.rest_day == "Monday" and mon not in resource.dayoff_ids: + resource.dayoff_ids = [(4, mon.id)] + elif data_id.rest_day == "Tuesday" and tue not in resource.dayoff_ids: + resource.dayoff_ids = [(4, tue.id)] + elif data_id.rest_day == "Wednesday" and wed not in resource.dayoff_ids: + resource.dayoff_ids = [(4, wed.id)] + elif data_id.rest_day == "Thursday" and thu not in resource.dayoff_ids: + resource.dayoff_ids = [(4, thu.id)] + elif data_id.rest_day == "Friday" and fri not in resource.dayoff_ids: + resource.dayoff_ids = [(4, fri.id)] + elif data_id.rest_day == "Saturday" and sat not in resource.dayoff_ids: + resource.dayoff_ids = [(4, sat.id)] + elif data_id.rest_day == "Sunday" and sun not in resource.dayoff_ids: + resource.dayoff_ids = [(4, sun.id)] diff --git a/hr_data_import/tests/test_import.py b/hr_data_import/tests/test_import.py index 705f6704..521a7a97 100644 --- a/hr_data_import/tests/test_import.py +++ b/hr_data_import/tests/test_import.py @@ -71,6 +71,7 @@ def setUpClass(cls): "name": "Default Policy Group", } ) + cls.default_rest_day = "Friday" cls.data = cls.DataImport.create( [ { @@ -87,6 +88,7 @@ def setUpClass(cls): "struct_id": cls.pay_structure.id, "pps_id": cls.pps.id, "policy_group_id": cls.policy_group.id, + "rest_day": cls.default_rest_day, }, { "name": "John Doe", @@ -119,6 +121,7 @@ def setUpClass(cls): "struct_id": cls.pay_structure.id, "pps_id": cls.pps.id, "policy_group_id": cls.policy_group.id, + "rest_day": cls.default_rest_day, } def test_workflow(self): @@ -178,6 +181,18 @@ def test_workflow(self): "trial", f"Employee's contract is in 'trial' state: {rec.name}", ) + if rec.rest_day: + self.assertEqual( + rec.related_employee_id.resource_id.dayoff_ids[0].name, + self.default_rest_day, + f"Employee's rest day matches imported record: {rec.name}", + ) + else: + self.assertFalse( + rec.related_employee_id.resource_id.dayoff_ids, + f"Employee's rest day is empty as no value was imported: {rec.name}", + ) + self.assertEqual( rec.state, "imported", @@ -221,3 +236,14 @@ def test_set_value_calendar(self): self.std_calendar, f"Calendar correctly set on employee contract: {ee.name}", ) + + def test_rest_day(self): + self.data[1].rest_day = self.default_rest_day + self.data.import_records() + ee = self.Employee.search([("name", "=", self.data[1].name)]) + self.assertTrue(ee, f"Found employee: {self.data[1].name}") + self.assertEqual( + ee.resource_id.dayoff_ids[0].name, + self.default_rest_day, + f"Calendar correctly set on employee contract: {ee.name}", + ) diff --git a/hr_data_import/views/hr_data_import_employee_views.xml b/hr_data_import/views/hr_data_import_employee_views.xml index d772f68f..c389735d 100644 --- a/hr_data_import/views/hr_data_import_employee_views.xml +++ b/hr_data_import/views/hr_data_import_employee_views.xml @@ -24,6 +24,11 @@ name="state_imported" domain="[('state', '=', 'imported')]" /> + + @@ -116,6 +122,7 @@ + @@ -174,4 +181,16 @@ action = records.action_import_employees() + + Update HR Records + + + list,form + code + action = records.action_update_employees() + + diff --git a/resource_schedule/README.rst b/resource_schedule/README.rst index 37337930..453bce24 100644 --- a/resource_schedule/README.rst +++ b/resource_schedule/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ========================= Employee Shift Scheduling ========================= @@ -17,12 +13,12 @@ Employee Shift Scheduling .. |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 +.. |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-trevi--software%2Ftrevi--hr-lightgray.png?logo=github - :target: https://github.com/trevi-software/trevi-hr/tree/14.0/resource_schedule - :alt: trevi-software/trevi-hr +.. |badge3| image:: https://img.shields.io/badge/github-TREVI Software%2Ftrevi--hr-lightgray.png?logo=github + :target: https://github.com/TREVI Software/trevi-hr/tree/14.0/resource_schedule + :alt: TREVI Software/trevi-hr |badge1| |badge2| |badge3| @@ -48,10 +44,10 @@ Known issues / Roadmap Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +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 to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -72,6 +68,6 @@ Other credits Maintainers ~~~~~~~~~~~ -This module is part of the `trevi-software/trevi-hr `_ project on GitHub. +This module is part of the `TREVI Software/trevi-hr `_ project on GitHub. You are welcome to contribute. diff --git a/resource_schedule/static/description/index.html b/resource_schedule/static/description/index.html index c2d6d780..a3a018c2 100644 --- a/resource_schedule/static/description/index.html +++ b/resource_schedule/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Employee Shift Scheduling -
+
+

Employee Shift Scheduling

- - -Odoo Community Association - -
-

Employee Shift Scheduling

-

Beta License: AGPL-3 trevi-software/trevi-hr

+

Beta License: AGPL-3 TREVI Software/trevi-hr

Easily create, manage, and track employee shift planning.

  1. Work Detail Templates - templates describe a shift for one day. For example: 8 a.m to 5 p.m.
  2. @@ -398,41 +393,40 @@

    Employee Shift Scheduling

-

Known issues / Roadmap

+

Known issues / Roadmap

  • When demo data is enabled and the module is updated you may encounter and error the the demo data failed to install. This error may safely be ignored.
-

Bug Tracker

-

Bugs are tracked on GitHub Issues. +

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 to smash it by providing a detailed and welcomed -feedback.

+feedback.

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

-

Credits

+

Credits

-

Authors

+

Authors

  • TREVI Software
  • Michael Telahun Makonnen
-

Other credits

+

Other credits

-

Maintainers

-

This module is part of the trevi-software/trevi-hr project on GitHub.

+

Maintainers

+

This module is part of the TREVI Software/trevi-hr project on GitHub.

You are welcome to contribute.

-
From 3082bf477af0c642eaa98d9f7ec283fa510ca4c5 Mon Sep 17 00:00:00 2001 From: Michael Telahun Makonnen Date: Sat, 22 Nov 2025 14:13:15 +0300 Subject: [PATCH 2/2] pre-commit autoupdate --- .pre-commit-config.yaml | 20 +++++++------- .../models/hr_data_import_employee.py | 2 +- resource_schedule/README.rst | 6 ++++- .../static/description/index.html | 26 ++++++++++++------- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 27d2406d..29839073 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,7 @@ repos: language: fail files: '[a-zA-Z0-9_]*/i18n/en\.po$' - repo: https://github.com/oca/maintainer-tools - rev: d5fab7ee87fceee858a3d01048c78a548974d935 + rev: 71aa4caec15e8c1456b4da19e9f39aa0aa7377a9 hooks: # update the NOT INSTALLABLE ADDONS section above - id: oca-update-pre-commit-excluded-addons @@ -54,14 +54,14 @@ repos: - --if-source-changed - --keep-source-digest - repo: https://github.com/OCA/odoo-pre-commit-hooks - rev: v0.0.25 + rev: v0.1.7 hooks: - id: oca-checks-odoo-module - id: oca-checks-po args: - --disable=po-pretty-format - repo: https://github.com/myint/autoflake - rev: v1.5.3 + rev: v2.3.1 hooks: - id: autoflake args: @@ -72,7 +72,7 @@ repos: - --remove-duplicate-keys - --remove-unused-variables - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 25.11.0 hooks: - id: black - repo: local @@ -106,7 +106,7 @@ repos: - "eslint-plugin-jsdoc@" - "globals@" - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: trailing-whitespace # exclude autogenerated files @@ -128,12 +128,12 @@ repos: - id: mixed-line-ending args: ["--fix=lf"] - repo: https://github.com/asottile/pyupgrade - rev: v2.7.2 + rev: v3.21.2 hooks: - id: pyupgrade args: ["--keep-percent-format"] - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 7.0.0 hooks: - id: isort name: isort except __init__.py @@ -141,7 +141,7 @@ repos: - --settings=. exclude: /__init__\.py$ - repo: https://github.com/acsone/setuptools-odoo - rev: 3.1.8 + rev: 3.3.1 hooks: - id: setuptools-odoo-make-default - id: setuptools-odoo-get-requirements @@ -151,13 +151,13 @@ repos: - --header - "# generated from manifests external_dependencies" - repo: https://github.com/PyCQA/flake8 - rev: 5.0.0 + rev: 7.3.0 hooks: - id: flake8 name: flake8 additional_dependencies: ["flake8-bugbear==20.1.4"] - repo: https://github.com/OCA/pylint-odoo - rev: 7.0.2 + rev: v9.3.22 hooks: - id: pylint_odoo name: pylint with optional checks diff --git a/hr_data_import/models/hr_data_import_employee.py b/hr_data_import/models/hr_data_import_employee.py index 0361bc42..62a6c04b 100644 --- a/hr_data_import/models/hr_data_import_employee.py +++ b/hr_data_import/models/hr_data_import_employee.py @@ -106,7 +106,7 @@ class ImportEmployee(models.Model): ("Friday", "Friday"), ("Saturday", "Saturday"), ("Sunday", "Sunday"), - ("out", False) + ("out", False), ] ) diff --git a/resource_schedule/README.rst b/resource_schedule/README.rst index 453bce24..dde4042a 100644 --- a/resource_schedule/README.rst +++ b/resource_schedule/README.rst @@ -1,3 +1,7 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + ========================= Employee Shift Scheduling ========================= @@ -13,7 +17,7 @@ Employee Shift Scheduling .. |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 +.. |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-TREVI Software%2Ftrevi--hr-lightgray.png?logo=github diff --git a/resource_schedule/static/description/index.html b/resource_schedule/static/description/index.html index a3a018c2..63bbda91 100644 --- a/resource_schedule/static/description/index.html +++ b/resource_schedule/static/description/index.html @@ -3,7 +3,7 @@ -Employee Shift Scheduling +README.rst -
-

Employee Shift Scheduling

+
+ + +Odoo Community Association + +
+

Employee Shift Scheduling

-

Beta License: AGPL-3 TREVI Software/trevi-hr

+

Beta License: AGPL-3 TREVI Software/trevi-hr

Easily create, manage, and track employee shift planning.

  1. Work Detail Templates - templates describe a shift for one day. For example: 8 a.m to 5 p.m.
  2. @@ -393,13 +398,13 @@

    Employee Shift Scheduling

-

Known issues / Roadmap

+

Known issues / Roadmap

  • When demo data is enabled and the module is updated you may encounter and error the the demo data failed to install. This error may safely be ignored.
-

Bug Tracker

+

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 to smash it by providing a detailed and welcomed @@ -407,26 +412,27 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • TREVI Software
  • Michael Telahun Makonnen
-

Other credits

+

Other credits

-

Maintainers

+

Maintainers

This module is part of the TREVI Software/trevi-hr project on GitHub.

You are welcome to contribute.

+