Skip to content
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

Add module user_group_rename #45

Merged
merged 1 commit into from
Dec 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'private_data_group',
'queue_job_auto_requeue',
'super_calendar',
'user_group_rename',
'web_email_field_new_tab',
],
'installable': True,
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ COPY private_data_group /mnt/extra-addons/private_data_group
COPY queue_job_auto_requeue /mnt/extra-addons/queue_job_auto_requeue
COPY super_calendar /mnt/extra-addons/super_calendar
COPY test_http_request /mnt/extra-addons/test_http_request
COPY user_group_rename /mnt/extra-addons/user_group_rename
COPY web_email_field_new_tab /mnt/extra-addons/web_email_field_new_tab

COPY .docker_files/main /mnt/extra-addons/main
Expand Down
29 changes: 29 additions & 0 deletions user_group_rename/README.rst
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)
4 changes: 4 additions & 0 deletions user_group_rename/__init__.py
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
14 changes: 14 additions & 0 deletions user_group_rename/__manifest__.py
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,
}
36 changes: 36 additions & 0 deletions user_group_rename/models.py
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.
Binary file added user_group_rename/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions user_group_rename/tests/__init__.py
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).
43 changes: 43 additions & 0 deletions user_group_rename/tests/test_group_rename.py
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