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

TA#66766 [16.0][MIG] web_custom_label #118

Merged
merged 3 commits into from
Jul 22, 2024
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 @@ -13,6 +13,7 @@
"depends": [
"web",
"resize_observer_error_catcher",
"web_custom_label",
],
"installable": True,
}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN pip3 install -r test-requirements.txt
USER odoo

COPY resize_observer_error_catcher /mnt/extra-addons/resize_observer_error_catcher
COPY web_custom_label /mnt/extra-addons/web_custom_label

COPY .docker_files/main /mnt/extra-addons/main
COPY .docker_files/odoo.conf /etc/odoo
103 changes: 103 additions & 0 deletions web_custom_label/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Web Custom Label

This module allows to easily modify the labels of a view without any development.

## Customizing Labels

In order to edit a label, you need to:

* Go to `Settings / Translations / Application Terms / Custom Labels`.
* Add a new custom label.
* Refresh your browser session in order to see the new label in your view.

Here is an example for products. We rename the field `Internal Reference` (default_code) with `SKU`.

![Custom Field List](static/description/custom_field_list.png?raw=true)

Note that we selected 2 models to modify; `Product` and `Product Template`.
This means we are modifying the label for both product templates and variants.

Now, if we go to any for product form view, we get the new label `SKU`.

![Product List](static/description/product_list.png?raw=true)

![Product Form](static/description/product_form.png?raw=true)

custom_field_list.png

## Customizing Placeholers

The module also allows to modify the placeholders of a form view.

Here, we set custom placeholders on the street fields of partners / addresses.

![Placeholder List](static/description/custom_placeholder_list.png?raw=true)

Partners have multiple form views in Odoo.

Here, we did not have to specify which form view to edit.
The new placeholders are set in both the main partner form and the contact address form.

![Partner Form](static/description/partner_form_with_placeholders.png?raw=true)

![Address Form](static/description/address_form_with_placeholders.png?raw=true)

## Customizing Helpers

It is possible to customize a field helper.

![Custom Field Help](static/description/custom_field_help.png?raw=true)

![Contact Field Help](static/description/contact_field_help.png?raw=true)

## Customizing Selection Fields

Fields of type ``Selection`` can be customized.

In the list view of custom labels, a new position ``Selection`` and a column ``Key`` were added.
The ``Key`` contains the technical value of the selection option to rename.

![Custom Selection Option](static/description/custom_selection_option.png?raw=true)

In the example above, the option ``contact`` of the field ``type`` of ``res.partner``
was renamed to ``Personne`` (in french).

In the form view of a contact, the term ``Contact`` is replaced with ``Personne``.

![Partner Contact Type](static/description/partner_contact_type.png?raw=true)

## Customizing Buttons

In order to customize an element of the view that is not a field, we need to target the element with an Xpath expression.

Let's say we want to customize the stock picking view and change the `VALIDATE` button to `TRANSFER`.

![Picking Form Before](static/description/picking_form_before.png?raw=true)

We add the custom label using an Xpath expression.

![Picking Custom Label](static/description/picking_custom_label.png?raw=true)

Then, the label is updated on the button.

![Picking Form After](static/description/picking_form_after.png?raw=true)

## Comparison with Odoo Studio

When using Odoo Studio to modify a label, an inherited view is created behind the scene.
Thus, each label added using Odoo Studio is coupled with the code.
It adds complexity to deployments, because if the inherited view changes,
the Studio customization may become incompatible.

Another downside is that when using Studio, you will need to edit every view of your model.
For example, products and partners have multiple form views. If you change one label, you will
need to change at multiple places.

The module `Web Custom Label` does not add additionnal XML.
It modifies the view at the rendering, according to the language of the user.
If the inherited view changes, the system will not fail.
You may however end up with a wrong label inside a view and have to adjust the custom label entry.

Contributors
------------
* Numigi (tm) and all its contributors (https://bit.ly/numigiens)
4 changes: 4 additions & 0 deletions web_custom_label/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024 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
19 changes: 19 additions & 0 deletions web_custom_label/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Web Custom Label",
"version": "16.0.1.0.0",
"author": "Numigi",
"maintainer": "Numigi",
"website": "https://bit.ly/numigi-com",
"license": "LGPL-3",
"category": "Project",
"summary": "Enable easily customizing view labels.",
"depends": ["web"],
"data": [
"views/custom_label.xml",
"security/ir.model.access.csv",
],
"installable": True,
}
157 changes: 157 additions & 0 deletions web_custom_label/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * web_custom_label
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-22 01:40+0000\n"
"PO-Revision-Date: 2024-07-22 01:40+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__active
msgid "Active"
msgstr "Actif"

#. module: web_custom_label
#: model:ir.model,name:web_custom_label.model_base
msgid "Base"
msgstr ""

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__create_uid
msgid "Created by"
msgstr "Créé par"

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__create_date
msgid "Created on"
msgstr "Créé le"

#. module: web_custom_label
#: model:ir.actions.act_window,name:web_custom_label.custom_label_action
#: model:ir.ui.menu,name:web_custom_label.custom_label_menu
#: model_terms:ir.ui.view,arch_db:web_custom_label.custom_label_list
#: model_terms:ir.ui.view,arch_db:web_custom_label.custom_label_search
msgid "Custom Labels"
msgstr "Libellés personnalisés"

#. module: web_custom_label
#: model:ir.model,name:web_custom_label.model_web_custom_label
msgid "Custom View Label"
msgstr "Libellés de vue personnalisés"

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__display_name
msgid "Display Name"
msgstr "Nom affiché"

#. module: web_custom_label
#: model:ir.model.fields.selection,name:web_custom_label.selection__web_custom_label__type___field
#: model_terms:ir.ui.view,arch_db:web_custom_label.custom_label_list
#: model_terms:ir.ui.view,arch_db:web_custom_label.custom_label_search
msgid "Field"
msgstr "Champ"

#. module: web_custom_label
#: model_terms:ir.ui.view,arch_db:web_custom_label.custom_label_search
msgid "Group By"
msgstr "Grouper par"

#. module: web_custom_label
#: model:ir.model.fields.selection,name:web_custom_label.selection__web_custom_label__position__help
msgid "Help"
msgstr "Aide"

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__id
msgid "ID"
msgstr ""

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__key
msgid "Key"
msgstr "Clé"

#. module: web_custom_label
#: model:ir.model.fields.selection,name:web_custom_label.selection__web_custom_label__position__string
msgid "Label"
msgstr "Libellé"

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__lang
#: model_terms:ir.ui.view,arch_db:web_custom_label.custom_label_search
msgid "Language"
msgstr "Langue"

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label____last_update
msgid "Last Modified on"
msgstr "Dernière modification le"

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__write_uid
msgid "Last Updated by"
msgstr "Dernière mise à jour par"

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__write_date
msgid "Last Updated on"
msgstr "Dernière mise à jour le"

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__model_ids
msgid "Model"
msgstr "Modèle"

#. module: web_custom_label
#: model:ir.model.fields.selection,name:web_custom_label.selection__web_custom_label__position__placeholder
msgid "Placeholder"
msgstr ""

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__position
msgid "Position"
msgstr ""

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__reference
msgid "Reference"
msgstr "Référence"

#. module: web_custom_label
#: model:ir.model.fields.selection,name:web_custom_label.selection__web_custom_label__position__selection
msgid "Selection"
msgstr ""

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__term
msgid "Term"
msgstr "Terme"

#. module: web_custom_label
#: model_terms:ir.ui.view,arch_db:web_custom_label.custom_label_search
msgid "Type"
msgstr ""

#. module: web_custom_label
#: model:ir.model.fields,field_description:web_custom_label.field_web_custom_label__type_
msgid "Type "
msgstr "Type"

#. module: web_custom_label
#: model:ir.model,name:web_custom_label.model_ir_ui_view
msgid "View"
msgstr "Vue"

#. module: web_custom_label
#: model:ir.model.fields.selection,name:web_custom_label.selection__web_custom_label__type___xpath
msgid "Xpath"
msgstr ""
8 changes: 8 additions & 0 deletions web_custom_label/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright 2024 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import (
base,
ir_ui_view,
web_custom_label,
)
23 changes: 23 additions & 0 deletions web_custom_label/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, models
from .common import set_custom_labels_on_fields


class Base(models.AbstractModel):

_inherit = "base"

@api.model
def fields_get(self, allfields=None, attributes=None):
"""Add the custom labels to the fields metadata.

The method is used to query the fields metadata.
This data is used by search filters / group by to display the field names.
"""
fields = super().fields_get(allfields, attributes)
lang = self.env.context.get("lang") or self.env.user.lang
labels = self.env["web.custom.label"].get(self._name, lang)
set_custom_labels_on_fields(labels, fields)
return fields
Loading
Loading