Skip to Content
Menu
This question has been flagged
2 Replies
2877 Views

Odoo 10/11 CE. This is classical. For example you chose first the brand 'f1' of a car, and next, depending of the brand you want to chose the model 'f2' in the brand.

Using @api.onchange('f1') returning a dictionary which defines the domain of f2 works well when you create a record.

It does not work when you use "edit", because the onchange event is not fired.

What is a solution to make it work in Edit mode?


Avatar
Discard
Best Answer

Dear Robert

Try This Also and Keep Onchange Function



from lxml import etree

    @api.model
    def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
        res = super(YourClassName, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
        doc = etree.XML(res['arch'])
        nodes = doc.xpath("//field[@name='your_specific_field']")
        for node in nodes:
            your_ids= []
            node.set('domain', str([('id', 'in', your_ids)]))

        res['arch'] = etree.tostring(doc)
        return res

I hope I helped You...

Avatar
Discard
Best Answer

if there is onchange in f1 even while writing it works. Try to change onchange with @api.depends('f1').

Avatar
Discard
Related Posts Replies Views Activity
2
Sep 22
7896
2
Apr 22
2462
0
Jul 21
5326
1
Mar 21
3344
5
Aug 20
16304