Skip to content

Commit

Permalink
Merge PR OCA#2426 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed Mar 9, 2024
2 parents f3fed5f + f63c4ff commit d872bb4
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup/web_tooltip_field/odoo/addons/web_tooltip_field
6 changes: 6 additions & 0 deletions setup/web_tooltip_field/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Empty file added web_tooltip_field/README.rst
Empty file.
4 changes: 4 additions & 0 deletions web_tooltip_field/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
from .patch import post_load
20 changes: 20 additions & 0 deletions web_tooltip_field/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Komit - Cuong Nguyen Mtm
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Web Tooltip Field",
"version": "14.0.1.0.0",
"summary": "Showing a Field ToolTip in Odoo",
"category": "Tools",
"website": "https://github.com/OCA/web",
"author": "KOMIT, Odoo Community Association (OCA)",
"maintainers": ["cuongnmtm"],
"license": "AGPL-3",
"depends": ["base", "web"],
"data": [
"security/ir.model.access.csv",
"views/ir_model_fields_help_tooltip_view.xml",
],
"post_load": "post_load",
"application": False,
"installable": True,
}
3 changes: 3 additions & 0 deletions web_tooltip_field/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import ir_model_fields_help_tooltip
24 changes: 24 additions & 0 deletions web_tooltip_field/models/ir_model_fields_help_tooltip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 Komit - Cuong Nguyen Mtm
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class IrModelFieldsHelpTooltip(models.Model):
_name = "ir.model.fields.help.tooltip"
_description = "Help Tooltip for Fields"
_rec_name = "field_id"

field_id = fields.Many2one(
"ir.model.fields", required=True, ondelete="cascade", index=True
)
model = fields.Char(related="field_id.model", store=True)
help = fields.Text(translate=True)

_sql_constraints = [
(
"field_id_uniq",
"unique(field_id)",
"Help Tooltip for Field already exists!",
),
]
27 changes: 27 additions & 0 deletions web_tooltip_field/patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import logging

from odoo.fields import Field

_logger = logging.getLogger(__name__)

_former_field_description_help = Field._description_help


def _description_help(self, env):
model_name = self.base_field.model_name
help_tooltip = env["ir.model.fields.help.tooltip"].search(
[
("field_id.name", "=", self.name),
("model", "=", model_name),
("help", "!=", ""),
],
limit=1,
)
if help_tooltip:
return help_tooltip.help
return _former_field_description_help(self, env)


def post_load():
_logger.info("Aplying patch web_tooltip_field ...")
Field._description_help = _description_help
3 changes: 3 additions & 0 deletions web_tooltip_field/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Komit <https://komit-consulting.com>`_:

* Cuong Nguyen Mtm <cuong.nmtm@komit-consulting.com>
4 changes: 4 additions & 0 deletions web_tooltip_field/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The development of this module has been financially supported by:

- Scaleway SAS (https://www.scaleway.com/)
- Komit (https://komit-consulting.com)
7 changes: 7 additions & 0 deletions web_tooltip_field/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Configure
=========
* Open debug mode.
* Go to Setting > Fields Help Tooltip.
* Choose a field and insert your help message for that field.

Then there will be a help message displayed when you mouserover it.
3 changes: 3 additions & 0 deletions web_tooltip_field/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_ir_model_fields_help_tooltip,ir.model.fields.help.tooltip,model_ir_model_fields_help_tooltip,base.group_system,1,1,1,1
access_ir_model_fields_help_tooltip_internal,ir.model.fields.help.tooltip,model_ir_model_fields_help_tooltip,base.group_user,1,0,0,0
3 changes: 3 additions & 0 deletions web_tooltip_field/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import test_field
30 changes: 30 additions & 0 deletions web_tooltip_field/tests/test_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2023 Komit - Cuong Nguyen Mtm
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.tests import common


class TestField(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestField, cls).setUpClass()

def test_field_description_help(self):
contact_user_id_field = self.env["res.partner"]._fields["user_id"]
self.assertEqual(
contact_user_id_field._description_help(self.env),
"The internal user in charge of this contact.",
)
contact_user_id_field_rec = self.env["ir.model.fields"].search(
[
("model", "=", "res.partner"),
("name", "=", "user_id"),
],
limit=1,
)
self.env["ir.model.fields.help.tooltip"].create(
{"field_id": contact_user_id_field_rec.id, "help": "This is a test help."}
)
self.assertEqual(
contact_user_id_field._description_help(self.env), "This is a test help."
)
86 changes: 86 additions & 0 deletions web_tooltip_field/views/ir_model_fields_help_tooltip_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2023 Komit - Cuong Nguyen Mtm
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record id="ir_model_fields_help_tooltip_view_tree" model="ir.ui.view">
<field name="name">ir.model.fields.help.tooltip.view.tree</field>
<field name="model">ir.model.fields.help.tooltip</field>
<field name="arch" type="xml">
<tree>
<field name="model" />
<field name="field_id" />
<field name="help" />
</tree>
</field>
</record>

<record id="ir_model_fields_help_tooltip_view_form" model="ir.ui.view">
<field name="name">ir.model.fields.help.tooltip.view.form</field>
<field name="model">ir.model.fields.help.tooltip</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<group>
<field name="field_id" />
<field name="help" />
</group>
<group>
<field name="model" />
</group>
</group>
</sheet>
</form>
</field>
</record>

<record id="ir_model_fields_help_tooltip_view_search" model="ir.ui.view">
<field name="name">ir.model.fields.help.tooltip.view.search</field>
<field name="model">ir.model.fields.help.tooltip</field>
<field name="arch" type="xml">
<search>
<field name="field_id" />
<field name="help" />
<group expand="0" string="Group By...">
<filter
string="Model"
name="groupby_model"
context="{'group_by': 'model'}"
/>
</group>
</search>
</field>
</record>

<record id="ir_model_fields_help_tooltip_action" model="ir.actions.act_window">
<field name="name">Fields Help Tooltip</field>
<field name="res_model">ir.model.fields.help.tooltip</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="ir_model_fields_help_tooltip_view_tree" />
<field name="search_view_id" ref="ir_model_fields_help_tooltip_view_search" />
</record>

<menuitem
id="ir_model_fields_help_tooltip_menu"
name="Fields Help Tooltip"
parent="base.next_id_9"
action="ir_model_fields_help_tooltip_action"
sequence="15"
/>

<!-- Change sequence of other menu to place ir_model_fields_help_tooltip_menu in the middle -->
<record id="base.ir_model_constraint_menu" model="ir.ui.menu">
<field name="sequence">20</field>
</record>
<record id="base.ir_model_relation_menu" model="ir.ui.menu">
<field name="sequence">25</field>
</record>
<record id="base.menu_action_attachment" model="ir.ui.menu">
<field name="sequence">30</field>
</record>
<record id="base.ir_logging_all_menu" model="ir.ui.menu">
<field name="sequence">35</field>
</record>

</odoo>

0 comments on commit d872bb4

Please sign in to comment.