-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bc156d
commit 763a4b2
Showing
12 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,29 @@ | ||
User Group Rename | ||
================= | ||
This module allows to rename a user group using XML data files in modules. | ||
|
||
This module is the same as ``menu_item_rename`` but for user groups instead of menu items. | ||
|
||
Usage | ||
----- | ||
Here is an example of usage in an XML file. | ||
|
||
.. code-block:: XML | ||
<function name="rename" model="res.groups"> | ||
<value type="char">account.group_account_user</value> | ||
<value type="char">fr_FR</value> | ||
<value type="char">Comptable</value> | ||
</function> | ||
Before loading the XML, the group is named ``Montrer les fonctions de comptabilité complète`` in french. | ||
|
||
.. image:: static/description/group_before.png | ||
|
||
After loading the XML, the group is named ``Comptable``. | ||
|
||
.. image:: static/description/group_after.png | ||
|
||
Contributors | ||
------------ | ||
* Numigi (tm) and all its contributors (https://bit.ly/numigiens) |
This file contains 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,4 @@ | ||
# © 2019 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import models |
This file contains 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,14 @@ | ||
# © 2019 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
{ | ||
'name': 'User Group Rename', | ||
'version': '1.0.0', | ||
'author': 'Numigi', | ||
'maintainer': 'Numigi', | ||
'license': 'LGPL-3', | ||
'category': 'Other', | ||
'summary': 'Rename user groups using module xml.', | ||
'depends': ['base'], | ||
'installable': True, | ||
} |
This file contains 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,36 @@ | ||
# © 2019 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
import logging | ||
from odoo import api, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class ResGroups(models.Model): | ||
|
||
_inherit = 'res.groups' | ||
|
||
@api.model | ||
def rename(self, group_ref, lang, value): | ||
"""Rename the user group. | ||
:param group_ref: the XML ID of the group | ||
:param lang: the language of the group | ||
:param value: the new name for the group | ||
""" | ||
_logger.info( | ||
'Renaming the user group {group_ref} with the label `{value}` ' | ||
'for the language {lang}.' | ||
.format(group_ref=group_ref, lang=lang, value=value) | ||
) | ||
group = self.env.ref(group_ref) | ||
if group._name != 'res.groups': | ||
raise ValidationError( | ||
'The XML ID {} does not reference a group.' | ||
.format(group_ref) | ||
) | ||
|
||
group.with_context(lang=lang).name = value |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,2 @@ | ||
# © 2019 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). |
This file contains 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,43 @@ | ||
# © 2019 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from odoo.tests import common | ||
|
||
|
||
class TestRenamegroupItem(common.SavepointCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.fr_lang = cls.env['res.lang'].with_context(active_test=False).search([ | ||
('code', '=', 'fr_FR'), | ||
]) | ||
cls.fr_lang.active = True | ||
|
||
cls.group_name_en = 'Access Rights' | ||
cls.group_name_fr = "Droits d'accès" | ||
cls.group = cls.env.ref('base.group_erp_manager') | ||
cls.group.with_context(lang='fr_FR').name = cls.group_name_fr | ||
|
||
def _rename_group(self, lang, label): | ||
self.env['res.groups'].rename('base.group_erp_manager', lang, label) | ||
|
||
def test_after_rename_group_with_fr__fr_translation_updated(self): | ||
new_label = 'Nouveau libellé' | ||
self._rename_group('fr_FR', new_label) | ||
assert self.group.with_context(lang='fr_FR').name == new_label | ||
|
||
def test_after_rename_group_with_fr__en_translation_unchanged(self): | ||
new_label = 'Nouveau libellé' | ||
self._rename_group('fr_FR', new_label) | ||
assert self.group.with_context(lang='en_US').name == self.group_name_en | ||
|
||
def test_after_rename_group_with_en__en_translation_updated(self): | ||
new_label = 'New label' | ||
self._rename_group('en_US', new_label) | ||
assert self.group.with_context(lang='en_US').name == new_label | ||
|
||
def test_after_rename_group_with_en__fr_translation_unchanged(self): | ||
new_label = 'New label' | ||
self._rename_group('en_US', new_label) | ||
assert self.group.with_context(lang='fr_FR').name == self.group_name_fr |