0

The case is extremely simple, yet, I cannot find any solution.

.py
model_a:
    field_b = fields.Many2one('model_b')

.xml
<tree string="List of model_a elements">
    <field name="field_b" />

I have a list view of "model_a". I would like to redirect the user to field_b's form when he clicks on a line.

Deadly simple, but is there a way to achieve this ?

ATX
  • 1,139
  • 2
  • 11
  • 29
  • 1
    This could only be done with changes in the tree web widget. An alternative is [Web Tree Many2one Clickable module by OCA](https://github.com/OCA/web/tree/12.0/web_tree_many2one_clickable) – CZoellner Nov 29 '19 at 10:07
  • You can use a button in your tree view to open another model Check my answer for a similar question https://stackoverflow.com/questions/45316649/odoo-10-open-a-form-view-in-an-editable-tree-view/45322819 – Charif DZ Nov 29 '19 at 14:02

2 Answers2

1

If anybody searches a solution for this. Here is a js snippet tested on odoo 15

Copy it to a file and make sure to load the file via __manifest__.py

Last thing to do: Change "from.model" and "to.model" to the one you need

odoo.define("nona.redirectToProduct", function (require) {
    "use strict";

    var ListRenderer = require("web.ListRenderer");
    ListRenderer.include({
        _renderRow: function (record) {
            let row = this._super(record);
            var self = this;
            if (record.model == "from.model") {
                row.addClass('o_list_no_open');
                // add click event
                row.bind({
                    click: function (ev) {
                        ev.preventDefault();
                        ev.stopPropagation();
                        self.do_action({
                            type: "ir.actions.act_window",
                            res_model: "to.model",
                            res_id: record.data.product_id,
                            views: [[false, "form"]],
                            target: "target",
                            context: record.context || {},
                        });
                    }
                });
            }
            return row
        },
    });
});
-1

you can do it easly by adding in the action view in xml field a from view like this

<record id="model_a_action" model="ir.actions.act_window">
    <field name="name">model.a.form.action</field>
    <field name="res_model">model.a</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
</record>
imad
  • 123
  • 8
  • 1
    Thanks. However this does not answers the question. The form view I want to reach is from "model b", from a tree list of "model a". – ATX Dec 02 '19 at 10:44
  • 1
    ah ok i have not seen model_b for your request this is the solution : https://apps.odoo.com/apps/modules/11.0/web_tree_many2one_clickable/ – imad Dec 02 '19 at 11:08