-
-
Notifications
You must be signed in to change notification settings - Fork 722
[MOD][18.0] hr_employee_language: languages selection #1517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mymage
wants to merge
1
commit into
OCA:18.0
Choose a base branch
from
mymage:18.0-mod-hr_employee_language
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| - Savoir-faire Linux (<http://www.savoirfairelinux.com>) | ||
| - François Honoré \<francois.honore@acsone.eu\> | ||
| - Saran Lim. \<saranl@ecosoft.co.th\> | ||
| - Stefano Consolaro \<stefano.consolaro@mymage.it\> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import test_add_lang |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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", | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.