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

[16.0][MIG] web_field_tooltip: Migration to 16.0 #2783

Merged
merged 7 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 setup/web_field_tooltip/odoo/addons/web_field_tooltip
6 changes: 6 additions & 0 deletions setup/web_field_tooltip/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,
)
15 changes: 7 additions & 8 deletions web_field_tooltip/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Web Field Tooltip
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:546620e49e8a51bd4af1d867397642b2810a3e7a0d30f39c06cd7d8454a96c43
!! source digest: sha256:6a4fafacb03368529d861e303732dce4c182ee511090cb4fd9ca04d67347bae0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -17,20 +17,19 @@ Web Field Tooltip
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/13.0/web_field_tooltip
:target: https://github.com/OCA/web/tree/16.0/web_field_tooltip
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-13-0/web-13-0-web_field_tooltip
:target: https://translation.odoo-community.org/projects/web-16-0/web-16-0-web_field_tooltip
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=13.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module gives the possibility to add tooltips next to fields labels on any
field of a model. The tooltip displays an html field that can contain links and
the name of the user that last updated it.
field of a model. The tooltip displays an html field.

**Table of contents**

Expand Down Expand Up @@ -65,7 +64,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_field_tooltip%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_field_tooltip%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -95,6 +94,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/web <https://github.com/OCA/web/tree/13.0/web_field_tooltip>`_ project on GitHub.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/16.0/web_field_tooltip>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
15 changes: 13 additions & 2 deletions web_field_tooltip/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Web Field Tooltip",
"summary": """
Displays customizable tooltips for fields""",
"version": "13.0.1.0.0",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web",
Expand All @@ -16,6 +16,17 @@
"security/ir_model_access.xml",
"views/ir_model_fields_tooltip.xml",
"views/res_users.xml",
"views/template.xml",
],
"assets": {
"web.assets_backend": [
"/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.esm.js",
"/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.scss",
"/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.xml",
"/web_field_tooltip/static/src/views/form/form_controller.esm.js",
"/web_field_tooltip/static/src/views/form/form_label.esm.js",
"/web_field_tooltip/static/src/views/form/form_label.xml",
"/web_field_tooltip/static/src/views/list/list_renderer.esm.js",
"/web_field_tooltip/static/src/views/list/list_renderer.xml",
],
},
}
1 change: 1 addition & 0 deletions web_field_tooltip/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import base
from . import ir_http
from . import ir_model_fields_tooltip
from . import res_users
29 changes: 29 additions & 0 deletions web_field_tooltip/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import api, models


class Base(models.AbstractModel):
_inherit = "base"

@api.model
def fields_get(self, allfields=None, attributes=None):
res = super().fields_get(allfields=allfields, attributes=attributes)
fnames = res.keys()
tooltips_data = (
self.env["ir.model.fields.tooltip"]
.sudo()
.search_read(
[
("model", "=", self._name),
("field_name", "in", list(fnames)),
],
[],
)
)
for tooltip_data in tooltips_data:
tooltip_fname = tooltip_data["field_name"]
res[tooltip_fname]["field_tooltip"] = tooltip_data

Check warning on line 28 in web_field_tooltip/models/base.py

View check run for this annotation

Codecov / codecov/patch

web_field_tooltip/models/base.py#L27-L28

Added lines #L27 - L28 were not covered by tests
return res
12 changes: 8 additions & 4 deletions web_field_tooltip/models/ir_model_fields_tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@
help="Model for the Field Tooltip.",
default=lambda self: self._get_default_model_id(),
)
model = fields.Char(related="model_id.model", string="Model Name")
model = fields.Char(related="model_id.model", string="Model Name", store=True)
field_id = fields.Many2one(
string="Field",
required=True,
comodel_name="ir.model.fields",
ondelete="cascade",
)
name = fields.Char(compute="_compute_name", readonly=True,)
field_name = fields.Char(related="field_id.name", store=True)
name = fields.Char(
compute="_compute_name",
readonly=True,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @benwillig, I created this PR to follow up your change to re-declaring the field_name (since the field_name below was not deleted, causing your store=True change to seem to be overwritten). but I wonder why this change is made because when the field_name is not stored, the module still functions properly

active = fields.Boolean(
default=True,
help="Set active to false to hide the Tooltip without removing it.",
)
field_name = fields.Char(related="field_id.name")
tooltip_text = fields.Html(string="Tooltip Text", required=True)
tooltip_text = fields.Html(required=True)

@api.model
def default_get(self, fields_list):
Expand All @@ -40,11 +44,11 @@
default_model = context.get("default_model")
default_field = context.get("default_field_name")
if default_model and default_field:
field = self.env["ir.model.fields"].search(

Check warning on line 47 in web_field_tooltip/models/ir_model_fields_tooltip.py

View check run for this annotation

Codecov / codecov/patch

web_field_tooltip/models/ir_model_fields_tooltip.py#L47

Added line #L47 was not covered by tests
[("model_id.model", "=", default_model), ("name", "=", default_field)],
limit=1,
)
res.update({"model_id": field.model_id.id, "field_id": field.id})

Check warning on line 51 in web_field_tooltip/models/ir_model_fields_tooltip.py

View check run for this annotation

Codecov / codecov/patch

web_field_tooltip/models/ir_model_fields_tooltip.py#L51

Added line #L51 was not covered by tests
return res

@api.constrains("model_id", "field_id")
Expand All @@ -61,7 +65,7 @@
raise UserError(_("A tooltip already exists for this field"))

def _get_default_model_id(self):
tooltip_model = self.env.context.get("tooltip_model")
tooltip_model = self.env.context.get("default_model")
model = self.env["ir.model"].search([("model", "=", tooltip_model)], limit=1)
return model.id or False

Expand Down
16 changes: 11 additions & 5 deletions web_field_tooltip/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@
compute="_compute_tooltip_show_add_helper_allowed"
)

def __init__(self, pool, cr):
super().__init__(pool, cr)
field_names = ["tooltip_show_add_helper"]
self.SELF_READABLE_FIELDS.extend(field_names)
self.SELF_WRITEABLE_FIELDS.extend(field_names)
@property
def TOOLTIP_READABLE_FIELDS(self):
return ["tooltip_show_add_helper"]

@property
def SELF_READABLE_FIELDS(self):
return super().SELF_READABLE_FIELDS + self.TOOLTIP_READABLE_FIELDS

@property
def SELF_WRITEABLE_FIELDS(self):
return super().SELF_WRITEABLE_FIELDS + self.TOOLTIP_READABLE_FIELDS

def _compute_tooltip_show_add_helper_allowed(self):
for rec in self:
rec.tooltip_show_add_helper_allowed = rec._is_tooltip_manager()

Check warning on line 33 in web_field_tooltip/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

web_field_tooltip/models/res_users.py#L33

Added line #L33 was not covered by tests

def _is_tooltip_manager(self):
self.ensure_one()
Expand Down
3 changes: 1 addition & 2 deletions web_field_tooltip/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
This module gives the possibility to add tooltips next to fields labels on any
field of a model. The tooltip displays an html field that can contain links and
the name of the user that last updated it.
field of a model. The tooltip displays an html field.
11 changes: 5 additions & 6 deletions web_field_tooltip/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,11 @@ <h1 class="title">Web Field Tooltip</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:546620e49e8a51bd4af1d867397642b2810a3e7a0d30f39c06cd7d8454a96c43
!! source digest: sha256:6a4fafacb03368529d861e303732dce4c182ee511090cb4fd9ca04d67347bae0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/13.0/web_field_tooltip"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-13-0/web-13-0-web_field_tooltip"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=13.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/16.0/web_field_tooltip"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-16-0/web-16-0-web_field_tooltip"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module gives the possibility to add tooltips next to fields labels on any
field of a model. The tooltip displays an html field that can contain links and
the name of the user that last updated it.</p>
field of a model. The tooltip displays an html field.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down Expand Up @@ -413,7 +412,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_field_tooltip%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_field_tooltip%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -437,7 +436,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/13.0/web_field_tooltip">OCA/web</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/16.0/web_field_tooltip">OCA/web</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/** @odoo-module */

import {Component, markup} from "@odoo/owl";

import {FormViewDialog} from "@web/views/view_dialogs/form_view_dialog";
import {session} from "@web/session";
import {usePopover} from "@web/core/popover/popover_hook";
import {useService} from "@web/core/utils/hooks";

export class FieldTooltipPopover extends Component {}
FieldTooltipPopover.template = "web_field_tooltip.FieldTooltipPopover";

export class FieldTooltip extends Component {
setup() {
this.popover = usePopover();
this.tooltipPopover = null;
this.hasFieldTooltip = this.props.hasFieldTooltip;
this.canManageTooltip = session.can_manage_tooltips;
this.showAddHelper =
session.can_manage_tooltips && session.tooltip_show_add_helper;
this.fieldTooltip = this.props.field.field_tooltip;

if (session.can_manage_tooltips) {
this.dialogService = useService("dialog");
}
}

get tooltipInfo() {
const props = this.props;
return {
title: props.field.string,
help: markup(this.tooltipText),
};
}

get tooltipText() {
return this.fieldTooltip.tooltip_text;
}

onClickTooltip(e) {
e.preventDefault();
e.stopPropagation();
if (!this.canManageTooltip) {
return;
}
const tooltipId = (this.fieldTooltip && this.fieldTooltip.id) || false;
this.dialogService.add(FormViewDialog, {
resModel: "ir.model.fields.tooltip",
resId: tooltipId,
context: {
default_model: this.props.resModel,
default_field_name: this.props.fieldName,
},
});
}

onMouseEnter(ev) {
if (!this.hasFieldTooltip) {
return;
}
this.closeTooltip();
this.tooltipPopover = this.popover.add(
ev.currentTarget,
FieldTooltipPopover,
this.tooltipInfo,
{
closeOnClickAway: true,
position: "top",
title: "title",
}
);
}

onMouseLeave() {
this.closeTooltip();
}

closeTooltip() {
if (this.tooltipPopover) {
this.tooltipPopover();
this.tooltipPopover = null;
}
}
}

FieldTooltip.template = "web_field_tooltip.FieldTooltip";
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
sup.field-tooltip {
.tooltip-icon {
background: none;
border: none;
display: inline-block;
width: fit-content;
margin-left: 0px;

&[has-tooltip] {
color: #666666 !important;
}
}

&:hover {
cursor: pointer;
}
}

.popup-div {
min-width: 100px;
min-height: 30px;

> * {
padding: 5px;
}

.popover-title {
font-weight: bold;
background-color: #f7f7f7;
}

.popover-content {
background-color: white;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>

<t t-name="web_field_tooltip.FieldTooltip" owl="1">
<sup
class="field-tooltip"
t-on-click="(ev) => this.onClickTooltip(ev)"
t-on-mouseenter="(ev) => this.onMouseEnter(ev)"
t-on-mouseleave="(ev) => this.onMouseLeave(ev)"
>
<a
class="fa fa fa-question-circle tooltip-icon text-info"
t-att-has-tooltip="props.hasFieldTooltip"
/>
</sup>
</t>

<t t-name="web_field_tooltip.FieldTooltipPopover" owl="1">
<div class="popup-div">
<div class="popover-title">
<span t-esc="props.title" />
</div>
<p class="popover-content">
<t t-out="props.help or ''" />
</p>
</div>
</t>

</templates>
23 changes: 0 additions & 23 deletions web_field_tooltip/static/src/css/web_field_tooltip.css

This file was deleted.

Loading
Loading