Skip to content

Commit

Permalink
[MIG] hr_employee_second_lastname: Migration to 17.0
Browse files Browse the repository at this point in the history
- Update module name to sicronize with partner_second_lastname.
- Update incoming parameters of post_init_hook method since `cr, registry`
  were replaced by `env` in [1].
- Deprecate the use of _onchange_spec method and use the method new method
  _get_fields_spec to return the fields specification from a view
  description since it was introduced in [2].
- Rename hooks file to follow guidelines.

[1] odoo/odoo@b4a7996
[2] odoo/odoo@f5e6494
  • Loading branch information
andreagidaltig committed Dec 4, 2023
1 parent e32c05e commit 917966f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 29 deletions.
16 changes: 4 additions & 12 deletions hr_employee_lastnames/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ HR Employee First Name and Two Last Names
: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/17.0/hr_employee_lastnames
:target: https://github.com/OCA/hr/tree/17.0/hr_employee_second_lastname
:alt: OCA/hr
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-17-0/hr-17-0-hr_employee_lastnames
:target: https://translation.odoo-community.org/projects/hr-17-0/hr-17-0-hr_employee_second_lastname
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/hr&target_branch=17.0
Expand Down Expand Up @@ -50,7 +50,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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_employee_lastnames%0Aversion:%2017.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_second_lastname%0Aversion:%2017.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 @@ -81,14 +81,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-luisg123v| image:: https://github.com/luisg123v.png?size=40px
:target: https://github.com/luisg123v
:alt: luisg123v

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-luisg123v|

This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/17.0/hr_employee_lastnames>`_ project on GitHub.
This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/17.0/hr_employee_second_lastname>`_ 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_lastnames/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "HR Employee First Name and Two Last Names",
"version": "16.0.1.0.2",
"version": "17.0.1.0.0",
"author": "Vauxoo, Odoo Community Association (OCA)",
"maintainers": ["luisg123v"],
"website": "https://github.com/OCA/hr",
Expand Down
9 changes: 2 additions & 7 deletions hr_employee_lastnames/hooks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from odoo import SUPERUSER_ID
from odoo.api import Environment


def post_init_hook(cr, _):
def post_init_hook(env):
# This SQL statement is necessary to call _install_employee_lastnames() and
# set name fields correctly.
#
Expand All @@ -23,7 +19,6 @@ def post_init_hook(cr, _):
# firstname = 'John'
# lastname = 'Peterson'
# lastname2 = 'Clinton'
cr.execute("UPDATE hr_employee SET firstname = NULL, lastname = NULL")
env = Environment(cr, SUPERUSER_ID, {})
env.cr.execute("UPDATE hr_employee SET firstname = NULL, lastname = NULL")
env["hr.employee"]._install_employee_lastnames()
env["ir.config_parameter"].sudo().set_param("employee_names_order", "first_last")
8 changes: 3 additions & 5 deletions hr_employee_lastnames/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">HR Employee First Name and Two Last Names</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e3ad9ca8445db84cea2f6b86336a239e2277e208c08820c7e4ea30ad9d259fe8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/hr/tree/17.0/hr_employee_lastnames"><img alt="OCA/hr" src="https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-17-0/hr-17-0-hr_employee_lastnames"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/hr&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/hr/tree/17.0/hr_employee_second_lastname"><img alt="OCA/hr" src="https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-17-0/hr-17-0-hr_employee_second_lastname"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/hr&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows you to add firstname and lastnames (Father an Mother
Last Name) in employee form, and concatenate both in name field.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -399,7 +399,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">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 to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/hr/issues/new?body=module:%20hr_employee_lastnames%0Aversion:%2017.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_second_lastname%0Aversion:%2017.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 All @@ -424,9 +424,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/luisg123v"><img alt="luisg123v" src="https://github.com/luisg123v.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr/tree/17.0/hr_employee_lastnames">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/17.0/hr_employee_second_lastname">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
18 changes: 14 additions & 4 deletions hr_employee_lastnames/tests/test_hr_employee_lastnames.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from odoo import exceptions
from odoo.tests.common import TransactionCase
from odoo.tools import submap


class TestEmployeeLastnames(TransactionCase):
Expand Down Expand Up @@ -45,9 +46,18 @@ def test_get_name_lastnames(self):

def test_onchange(self):
"""Validate the _get_name_lastnames method is not failing"""
field_onchange = self.employee_model.new({})._onchange_spec()
self.assertEqual(field_onchange.get("firstname"), "1")
self.assertEqual(field_onchange.get("lastname"), "1")
# Check that fields used to generate the name and also name field
# are empty before onchange
fields_spec = self.env["hr.employee"]._get_fields_spec()
self.assertEqual(
submap(fields_spec, ("firstname", "lastname", "lastname2", "name")),
{
"firstname": {},
"lastname": {},
"lastname2": {},
"name": {},
},
)
values = {
"firstname": "Pedro",
"lastname": "Perez",
Expand All @@ -61,7 +71,7 @@ def test_onchange(self):
new_record = self.employee_model.new(values)

updates = new_record.onchange(
values, ["firstname", "lastname", "lastname2"], field_onchange
values, ["firstname", "lastname", "lastname2"], fields_spec
)
values.update(updates.get("value", {}))
self.assertEqual(values["name"], "Pedro Perez Hernandez")
Expand Down

0 comments on commit 917966f

Please sign in to comment.