Skip to content

Commit

Permalink
[MIG] hr_employee_relative: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ppyczko committed Sep 5, 2024
1 parent dc48bd7 commit 1b93777
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 12 deletions.
5 changes: 5 additions & 0 deletions hr_employee_relative/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ Contributors
- Alberto Nieto de Pablos <[email protected]>
(https://braintec.com)

- `APSL-Nagarro <https://apsl.tech>`__:

- Patryk Pyczko [email protected]
- Bernat Obrador [email protected]

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion hr_employee_relative/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
15 changes: 12 additions & 3 deletions hr_employee_relative/models/hr_employee_relative.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Check warning on line 46 in hr_employee_relative/models/hr_employee_relative.py

View check run for this annotation

Codecov / codecov/patch

hr_employee_relative/models/hr_employee_relative.py#L44-L46

Added lines #L44 - L46 were not covered by tests

@api.onchange("partner_id")
def _onchange_partner_id(self):
Expand Down
3 changes: 3 additions & 0 deletions hr_employee_relative/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
- Nattapong W. \<<[email protected]>\>
- Alberto Nieto de Pablos \<<[email protected]>\>
(<https://braintec.com>)
* [APSL-Nagarro](<https://apsl.tech>):
* Patryk Pyczko <[email protected]>
* Bernat Obrador <[email protected]>
5 changes: 5 additions & 0 deletions hr_employee_relative/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<li>Nattapong W. &lt;<a class="reference external" href="mailto:aphon61bank&#64;gmail.com">aphon61bank&#64;gmail.com</a>&gt;</li>
<li>Alberto Nieto de Pablos &lt;<a class="reference external" href="mailto:alberto.nieto&#64;braintec.com">alberto.nieto&#64;braintec.com</a>&gt;
(<a class="reference external" href="https://braintec.com">https://braintec.com</a>)</li>
<li><a class="reference external" href="https://apsl.tech">APSL-Nagarro</a>:<ul>
<li>Patryk Pyczko <a class="reference external" href="mailto:ppyczko&#64;apsl.net">ppyczko&#64;apsl.net</a></li>
<li>Bernat Obrador <a class="reference external" href="mailto:bobrador&#64;apsl.net">bobrador&#64;apsl.net</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
19 changes: 12 additions & 7 deletions hr_employee_relative/tests/test_hr_employee_relatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@


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(
Expand All @@ -34,9 +35,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
Expand Down
4 changes: 3 additions & 1 deletion hr_employee_relative/views/hr_employee_relative.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<field name="partner_id" />
<field name="gender" />
<field name="date_of_birth" />
<field name="age" />
<field name="age_year" string="Age (Years)" />
<field name="age_month" string="Age (Months)" optional="hide" />
<field name="age_day" string="Age (Days)" optional="hide" />
<field name="phone_number" />
<field name="job" />
<field name="notes" />
Expand Down

0 comments on commit 1b93777

Please sign in to comment.