diff --git a/hr_employee_language/README.rst b/hr_employee_language/README.rst index b52232bcdb6..3d49b143f6c 100644 --- a/hr_employee_language/README.rst +++ b/hr_employee_language/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 - ==================== HR Employee Language ==================== @@ -17,7 +13,7 @@ HR Employee Language .. |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-OCA%2Fhr-lightgray.png?logo=github @@ -75,6 +71,7 @@ Contributors - Savoir-faire Linux (http://www.savoirfairelinux.com) - François Honoré - Saran Lim. +- Stefano Consolaro Maintainers ----------- diff --git a/hr_employee_language/models/hr_employee_language.py b/hr_employee_language/models/hr_employee_language.py index 15750f4ee54..7fe5b89cfcb 100644 --- a/hr_employee_language/models/hr_employee_language.py +++ b/hr_employee_language/models/hr_employee_language.py @@ -1,19 +1,36 @@ # Copyright (C) 2017-Today: Odoo Community Association (OCA) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import fields, models, tools +from odoo import fields, models class HrEmployeeLanguage(models.Model): _name = "hr.employee.language" _description = "HR Employee Language" - name = fields.Selection( - tools.misc.scan_languages(), string="Language", required=True - ) + def _get_selection(self): + """ + generate language selection from available on db + """ + selection = [] + for lang in self.env["res.lang"].search([("active", "in", (True, False))]): + selection.append((lang.code, lang.name)) + return selection + + name = fields.Selection(_get_selection, string="Language", required=True) description = fields.Char() employee_id = fields.Many2one("hr.employee", string="Employee", required=True) can_read = fields.Boolean(string="Read", default=True) can_write = fields.Boolean(string="Write", default=True) can_speak = fields.Boolean(string="Speak", default=True) can_listen = fields.Boolean(string="Listen", default=True) + + def _compute_display_name(self): + """ + redefine record display_name to show languages name instead languages code + """ + for record in self: + lang = self.env["res.lang"].search( + [("code", "=", record.name), ("active", "in", (True, False))], limit=1 + ) + record.display_name = lang.name if lang.name else record.name diff --git a/hr_employee_language/readme/CONTRIBUTORS.md b/hr_employee_language/readme/CONTRIBUTORS.md index 8fe3613a5b0..3a329cb4ff3 100644 --- a/hr_employee_language/readme/CONTRIBUTORS.md +++ b/hr_employee_language/readme/CONTRIBUTORS.md @@ -1,3 +1,4 @@ - Savoir-faire Linux () - François Honoré \ - Saran Lim. \ +- Stefano Consolaro \ diff --git a/hr_employee_language/static/description/index.html b/hr_employee_language/static/description/index.html index ce5dca39cc2..8aff27d39c2 100644 --- a/hr_employee_language/static/description/index.html +++ b/hr_employee_language/static/description/index.html @@ -3,16 +3,15 @@ -README.rst +HR Employee Language -
+
+

HR Employee Language

- - -Odoo Community Association - -
-

HR Employee Language

-

Beta License: AGPL-3 OCA/hr Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/hr Translate me on Weblate Try me on Runboat

This module allows you to manage your employee languages.

Table of contents

@@ -390,7 +384,7 @@

HR Employee Language

-

Usage

+

Usage

To use this module, you need to:

  • Go to Employees > select or create a new employee.
  • @@ -400,7 +394,7 @@

    Usage

    Languages

-

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 @@ -408,28 +402,27 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Savoir-faire Linux
  • Acsone
-

Maintainers

+

Maintainers

This module is maintained by the OCA.

- -Odoo Community Association - +Odoo Community Association

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.

@@ -438,6 +431,5 @@

Maintainers

-
diff --git a/hr_employee_language/tests/__init__.py b/hr_employee_language/tests/__init__.py new file mode 100644 index 00000000000..3ceaa81fcf3 --- /dev/null +++ b/hr_employee_language/tests/__init__.py @@ -0,0 +1 @@ +from . import test_add_lang diff --git a/hr_employee_language/tests/test_add_lang.py b/hr_employee_language/tests/test_add_lang.py new file mode 100644 index 00000000000..f2aa2b99d39 --- /dev/null +++ b/hr_employee_language/tests/test_add_lang.py @@ -0,0 +1,40 @@ +from odoo.tests.common import TransactionCase + + +class TestAddLanguage(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + def test_add_lang(self): + lang_list = self.env["res.lang"].search( + [("active", "in", (True, False))], limit=1 + ) + lang_old = lang_list.code + selection = self.env["hr.employee.language"]._get_selection() + selection_ck = any(map(lambda t: lang_old in t, selection)) + # Test if a old lang is present + self.assertEqual(selection_ck, True, "Old language is present") + + self.env["res.lang"].create({"code": "xx_XX", "name": "Foo"}) + selection = self.env["hr.employee.language"]._get_selection() + selection_ck = any(map(lambda t: "xx_XX" in t, selection)) + # Test if a new lang is present + self.assertEqual(selection_ck, True, "New language is present") + + def test_compute_display_name(self): + self.env["hr.employee.language"].create( + { + "name": "en_GB", + "employee_id": self.env["hr.employee"].create({"name": "Test"}).id, + } + ) + self.env["hr.employee.language"]._compute_display_name() + lang_ref = self.env["res.lang"].search( + [("code", "=", "en_GB"), ("active", "in", (True, False))], limit=1 + ) + self.assertEqual( + lang_ref.name, + "English (UK)", + "_compute_display_name not returns right value", + )