[17.0][MIG] web_tree_many2one_clickable

pull/2807/head
maciej-wichowski 2024-04-01 12:37:28 +02:00
parent 12bd36f07f
commit 2ce565e9ab
6 changed files with 26 additions and 31 deletions

View File

@ -88,6 +88,7 @@ Contributors
- Anand Kansagra <kansagraanand@hotmail.com> - Anand Kansagra <kansagraanand@hotmail.com>
- Alexandre Díaz <alexandre.diaz@tecnativa.com> - Alexandre Díaz <alexandre.diaz@tecnativa.com>
- Dennis Sluijk <d.sluijk@onestein.nl> - Dennis Sluijk <d.sluijk@onestein.nl>
- Maciej Wichowski <maciej@versada.eu>
Maintainers Maintainers
----------- -----------

View File

@ -7,7 +7,7 @@
{ {
"name": "Clickable many2one fields for tree views", "name": "Clickable many2one fields for tree views",
"summary": "Open the linked resource when clicking on their name", "summary": "Open the linked resource when clicking on their name",
"version": "16.0.1.0.0", "version": "17.0.1.0.0",
"category": "Hidden", "category": "Hidden",
"website": "https://github.com/OCA/web", "website": "https://github.com/OCA/web",
"author": "Therp BV, " "author": "Therp BV, "

View File

@ -6,3 +6,4 @@
- Anand Kansagra \<<kansagraanand@hotmail.com>\> - Anand Kansagra \<<kansagraanand@hotmail.com>\>
- Alexandre Díaz \<<alexandre.diaz@tecnativa.com>\> - Alexandre Díaz \<<alexandre.diaz@tecnativa.com>\>
- Dennis Sluijk \<<d.sluijk@onestein.nl>\> - Dennis Sluijk \<<d.sluijk@onestein.nl>\>
- Maciej Wichowski \<<maciej@versada.eu>\>

View File

@ -430,6 +430,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<li>Anand Kansagra &lt;<a class="reference external" href="mailto:kansagraanand&#64;hotmail.com">kansagraanand&#64;hotmail.com</a>&gt;</li> <li>Anand Kansagra &lt;<a class="reference external" href="mailto:kansagraanand&#64;hotmail.com">kansagraanand&#64;hotmail.com</a>&gt;</li>
<li>Alexandre Díaz &lt;<a class="reference external" href="mailto:alexandre.diaz&#64;tecnativa.com">alexandre.diaz&#64;tecnativa.com</a>&gt;</li> <li>Alexandre Díaz &lt;<a class="reference external" href="mailto:alexandre.diaz&#64;tecnativa.com">alexandre.diaz&#64;tecnativa.com</a>&gt;</li>
<li>Dennis Sluijk &lt;<a class="reference external" href="mailto:d.sluijk&#64;onestein.nl">d.sluijk&#64;onestein.nl</a>&gt;</li> <li>Dennis Sluijk &lt;<a class="reference external" href="mailto:d.sluijk&#64;onestein.nl">d.sluijk&#64;onestein.nl</a>&gt;</li>
<li>Maciej Wichowski &lt;<a class="reference external" href="mailto:maciej&#64;versada.eu">maciej&#64;versada.eu</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">

View File

@ -5,29 +5,29 @@
* Copyright 2017 Sodexis <dev@sodexis.com> * Copyright 2017 Sodexis <dev@sodexis.com>
* Copyright 2018 Camptocamp SA * Copyright 2018 Camptocamp SA
* Copyright 2019 Alexandre Díaz <alexandre.diaz@tecnativa.com> * Copyright 2019 Alexandre Díaz <alexandre.diaz@tecnativa.com>
* Copyright 2024 Versada (https://versada.eu)
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
import {patch} from "@web/core/utils/patch";
import {ListRenderer} from "@web/views/list/list_renderer"; import {ListRenderer} from "@web/views/list/list_renderer";
import {Component} from "@odoo/owl";
import {useService} from "@web/core/utils/hooks"; import {useService} from "@web/core/utils/hooks";
export class TreeMany2oneClickableButton extends Component { patch(ListRenderer.prototype, {
setup() { setup() {
this.actionService = useService("action"); this.actionService = useService("action");
} super.setup(...arguments);
},
async onClick(ev) { async onClickM2oButton(record, column, ev) {
ev.stopPropagation(); ev.stopPropagation();
const field = record.fields[column.name];
const value = record.data[column.name];
return this.actionService.doAction({ return this.actionService.doAction({
type: "ir.actions.act_window", type: "ir.actions.act_window",
res_model: this.props.field.relation, res_model: field.relation,
res_id: this.props.value[0], res_id: value[0],
views: [[false, "form"]], views: [[false, "form"]],
target: "target", target: "target",
additionalContext: this.props.context || {}, additionalContext: column.context || {},
}); });
} },
} });
TreeMany2oneClickableButton.template = "web_tree_many2one_clickable.Button";
Object.assign(ListRenderer.components, {TreeMany2oneClickableButton});

View File

@ -1,21 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<templates> <templates>
<t t-name="web_tree_many2one_clickable.Button" owl="1">
<button
class="btn btn-sm btn-secondary fa fa-arrow-right web_tree_many2one_clickable"
t-on-click="onClick"
>
</button>
</t>
<t t-inherit="web.ListRenderer.RecordRow" t-inherit-mode="extension"> <t t-inherit="web.ListRenderer.RecordRow" t-inherit-mode="extension">
<xpath expr="//Field" position="after"> <xpath expr="//t[@t-if='!isInvisible']" position="inside">
<TreeMany2oneClickableButton <button
record="record" class="btn btn-sm btn-secondary fa fa-arrow-right web_tree_many2one_clickable"
field="record.fields[column.name]" t-on-click="(ev) => this.onClickM2oButton(record, column, ev)"
value="record.data[column.name]" t-if="record.fields[column.name].type == 'many2one' and record.data[column.name] and canUseFormatter(column, record) and !column.options.no_open"
t-if="record.fields[column.name].type == 'many2one' and record.data[column.name] and canUseFormatter(column, record) and !props.archInfo.fieldNodes[column.name].options.no_open" >
/> </button>
</xpath> </xpath>
</t> </t>
</templates> </templates>