[17.0][MIG] web_tree_many2one_clickable

This commit is contained in:
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

@@ -5,29 +5,29 @@
* Copyright 2017 Sodexis <dev@sodexis.com>
* Copyright 2018 Camptocamp SA
* 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). */
import {patch} from "@web/core/utils/patch";
import {ListRenderer} from "@web/views/list/list_renderer";
import {Component} from "@odoo/owl";
import {useService} from "@web/core/utils/hooks";
export class TreeMany2oneClickableButton extends Component {
patch(ListRenderer.prototype, {
setup() {
this.actionService = useService("action");
}
async onClick(ev) {
super.setup(...arguments);
},
async onClickM2oButton(record, column, ev) {
ev.stopPropagation();
const field = record.fields[column.name];
const value = record.data[column.name];
return this.actionService.doAction({
type: "ir.actions.act_window",
res_model: this.props.field.relation,
res_id: this.props.value[0],
res_model: field.relation,
res_id: value[0],
views: [[false, "form"]],
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" ?>
<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">
<xpath expr="//Field" position="after">
<TreeMany2oneClickableButton
record="record"
field="record.fields[column.name]"
value="record.data[column.name]"
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"
/>
<xpath expr="//t[@t-if='!isInvisible']" position="inside">
<button
class="btn btn-sm btn-secondary fa fa-arrow-right web_tree_many2one_clickable"
t-on-click="(ev) => this.onClickM2oButton(record, column, ev)"
t-if="record.fields[column.name].type == 'many2one' and record.data[column.name] and canUseFormatter(column, record) and !column.options.no_open"
>
</button>
</xpath>
</t>
</templates>