From e5b2deea3f03bcc10a3517a6df037b86314ff2ee Mon Sep 17 00:00:00 2001 From: Patryk Pyczko Date: Wed, 17 Jul 2024 09:05:24 +0200 Subject: [PATCH] [MIG] hr_employee_relative: Migration to 17.0 --- hr_employee_relative/README.rst | 5 +++++ hr_employee_relative/__manifest__.py | 2 +- .../models/hr_employee_relative.py | 15 ++++++++++--- hr_employee_relative/readme/CONTRIBUTORS.md | 3 +++ .../static/description/index.html | 5 +++++ .../tests/test_hr_employee_relatives.py | 22 ++++++++++--------- .../views/hr_employee_relative.xml | 4 +++- 7 files changed, 41 insertions(+), 15 deletions(-) diff --git a/hr_employee_relative/README.rst b/hr_employee_relative/README.rst index 1ba63c2def5..703bb6877d7 100644 --- a/hr_employee_relative/README.rst +++ b/hr_employee_relative/README.rst @@ -65,6 +65,11 @@ Contributors - Alberto Nieto de Pablos (https://braintec.com) +- `APSL-Nagarro `__: + + - Patryk Pyczko ppyczko@apsl.net + - Bernat Obrador bobrador@apsl.net + Maintainers ----------- diff --git a/hr_employee_relative/__manifest__.py b/hr_employee_relative/__manifest__.py index d6c1f3f27eb..aeeb32dbc1d 100644 --- a/hr_employee_relative/__manifest__.py +++ b/hr_employee_relative/__manifest__.py @@ -4,7 +4,7 @@ { "name": "HR Employee Relatives", - "version": "16.0.1.0.0", + "version": "17.0.1.0.0", "category": "Human Resources", "website": "https://github.com/OCA/hr", "author": "CorporateHub, Odoo Community Association (OCA)", diff --git a/hr_employee_relative/models/hr_employee_relative.py b/hr_employee_relative/models/hr_employee_relative.py index 21ed4c63e73..f7258bfde55 100644 --- a/hr_employee_relative/models/hr_employee_relative.py +++ b/hr_employee_relative/models/hr_employee_relative.py @@ -23,7 +23,9 @@ class HrEmployeeRelative(models.Model): selection=[("male", "Male"), ("female", "Female"), ("other", "Other")], ) date_of_birth = fields.Date() - age = fields.Float(compute="_compute_age") + age_year = fields.Integer(string="Age (Years)", compute="_compute_age") + age_month = fields.Integer(string="Age (Months)") + age_day = fields.Integer(string="Age (Days)") job = fields.Char() phone_number = fields.Char() @@ -33,8 +35,15 @@ class HrEmployeeRelative(models.Model): @api.depends("date_of_birth") def _compute_age(self): for record in self: - age = relativedelta(datetime.now(), record.date_of_birth) - record.age = age.years + (age.months / 12) + if record.date_of_birth: + age = relativedelta(datetime.now(), record.date_of_birth) + record.age_year = age.years + record.age_month = age.months + record.age_day = age.days + else: + record.age_year = 0 + record.age_month = 0 + record.age_day = 0 @api.onchange("partner_id") def _onchange_partner_id(self): diff --git a/hr_employee_relative/readme/CONTRIBUTORS.md b/hr_employee_relative/readme/CONTRIBUTORS.md index e28fcdbfddc..fb20a5a7816 100644 --- a/hr_employee_relative/readme/CONTRIBUTORS.md +++ b/hr_employee_relative/readme/CONTRIBUTORS.md @@ -4,3 +4,6 @@ - Nattapong W. \<\> - Alberto Nieto de Pablos \<\> () +* [APSL-Nagarro](): + * Patryk Pyczko + * Bernat Obrador \ No newline at end of file diff --git a/hr_employee_relative/static/description/index.html b/hr_employee_relative/static/description/index.html index 2dd5610137f..518ade97ea9 100644 --- a/hr_employee_relative/static/description/index.html +++ b/hr_employee_relative/static/description/index.html @@ -410,6 +410,11 @@

Contributors

  • Nattapong W. <aphon61bank@gmail.com>
  • Alberto Nieto de Pablos <alberto.nieto@braintec.com> (https://braintec.com)
  • +
  • APSL-Nagarro: +
  • diff --git a/hr_employee_relative/tests/test_hr_employee_relatives.py b/hr_employee_relative/tests/test_hr_employee_relatives.py index 3d5d02fc34f..8f94946fc7f 100644 --- a/hr_employee_relative/tests/test_hr_employee_relatives.py +++ b/hr_employee_relative/tests/test_hr_employee_relatives.py @@ -2,18 +2,16 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from datetime import datetime - from dateutil.relativedelta import relativedelta - from odoo.tests import Form, common - class TestHrEmployeeRelatives(common.TransactionCase): - def setUp(self): - super().setUp() - self.Employee = self.env["hr.employee"] - self.EmployeeRelative = self.env["hr.employee.relative"] - self.relation_sibling = self.env.ref("hr_employee_relative.relation_sibling") + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.Employee = cls.env["hr.employee"] + cls.EmployeeRelative = cls.env["hr.employee.relative"] + cls.relation_sibling = cls.env.ref("hr_employee_relative.relation_sibling") def test_age_calculation(self): employee = self.Employee.create( @@ -34,9 +32,13 @@ def test_age_calculation(self): } ) relative = self.EmployeeRelative.browse(employee.relative_ids[0].id) - self.assertEqual(int(relative.age), 42) + + self.assertEqual(relative.age_year, 42) + self.assertEqual(relative.age_month, 0) + self.assertEqual(relative.age_day, 0) self.assertEqual(relative.name, "Relative") - # onchange partner + + # Test onchange partner with Form(relative) as f: f.partner_id = self.env.ref("base.res_partner_2") f.relation_id = self.relation_sibling diff --git a/hr_employee_relative/views/hr_employee_relative.xml b/hr_employee_relative/views/hr_employee_relative.xml index b1ddd11673e..c009c79450a 100644 --- a/hr_employee_relative/views/hr_employee_relative.xml +++ b/hr_employee_relative/views/hr_employee_relative.xml @@ -14,7 +14,9 @@ - + + +