Skip to content

Commit

Permalink
[16.0][MIG] web_custom_label
Browse files Browse the repository at this point in the history
  • Loading branch information
lanto-razafindrabe committed Jul 9, 2024
1 parent f285f69 commit ad7793d
Show file tree
Hide file tree
Showing 30 changed files with 934 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
name: Setup Log Folder For Reports
command: sudo mkdir -p .log && sudo chmod 777 .log

# - run:
# name: Run Test
# command: docker-compose run --rm odoo run_pytest.sh
- run:
name: Run Test
command: docker-compose run --rm odoo run_pytest.sh

# - run:
# name: Codacy Coverage
Expand Down
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,
}
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ ARG GIT_TOKEN
COPY .docker_files/test-requirements.txt .
RUN pip3 install -r test-requirements.txt

# ENV THIRD_PARTY_ADDONS /mnt/third-party-addons
# RUN mkdir -p "${THIRD_PARTY_ADDONS}" && chown -R odoo "${THIRD_PARTY_ADDONS}"
# COPY ./gitoo.yml /gitoo.yml
# RUN gitoo install-all --conf_file /gitoo.yml --destination "${THIRD_PARTY_ADDONS}"
ENV THIRD_PARTY_ADDONS /mnt/third-party-addons
RUN mkdir -p "${THIRD_PARTY_ADDONS}" && chown -R odoo "${THIRD_PARTY_ADDONS}"
COPY ./gitoo.yml /gitoo.yml
RUN if [ -s /gitoo.yml ]; then \
gitoo install-all --conf_file /gitoo.yml --destination "${THIRD_PARTY_ADDONS}"; \
fi


COPY .docker_files/test-requirements.txt .
RUN pip3 install -r test-requirements.txt

USER odoo

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

COPY .docker_files/main /mnt/extra-addons/main
Expand Down
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 2023 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

Check notice on line 4 in web_custom_label/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web_custom_label/__init__.py#L4

'.models' imported but unused (F401)
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 2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{

Check warning on line 4 in web_custom_label/__manifest__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web_custom_label/__manifest__.py#L4

Statement seems to have no effect
"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": ["base"],
"data": [
"views/custom_label.xml",
"security/ir.model.access.csv",
],
"installable": True,
}
159 changes: 159 additions & 0 deletions web_custom_label/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * web_custom_label
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-17 19:52+0000\n"
"PO-Revision-Date: 2024-07-04 14:52-0500\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 2.0.6\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_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
#: selection:web.custom.label,type_:0
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
#: selection:web.custom.label,position:0
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 "ID"

#. 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
#: selection:web.custom.label,position:0
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
#: selection:web.custom.label,position:0
msgid "Placeholder"
msgstr "Texte substitution (placeholder)"

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

#. 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
#: selection:web.custom.label,position:0
msgid "Selection"
msgstr "Sélection"

#. 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 "Type"

#. 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
#: selection:web.custom.label,type_:0
msgid "Xpath"
msgstr "Xpath"
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 2023 - 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 (

Check notice on line 4 in web_custom_label/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web_custom_label/models/__init__.py#L4

'.base' imported but unused (F401)
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 2023 - 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

0 comments on commit ad7793d

Please sign in to comment.