Skip to Content
Menu
This question has been flagged
2064 Views

I have a many2many field where as I select the fields they should be dynamically represented on a page inside the notebook. I can dynamically create the page inside the notebook, but I can't introduce fields inside the respective page. I'm using etree to be able to manipulate the XML inside the Python file, but I can't finish the project, does anyone have any suggestions?

Python code:

@api.model
def fields_view_get(self, view_id=None, view_type="form", toolbar=False, submenu=False):
    res = super().fields_view_get(
        view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
    )
    if view_type == "form":
        doc = etree.XML(res["arch"])
        form_view_id = self.env['ir.model.data']._xmlid_to_res_id('texponto_product_customization.product_customization_template_view_form')
        if res.get('view_id') == form_view_id:
            target = doc.xpath("//notebook")
            if target:
                target = target[0]
                if not doc.xpath("//page[@name='Test']"):
                    target.append(doc.makeelement("page", {"name": "Test", "string": "Test1"}) , "field", {"name": "customizable_lines_ids"}, "tree", {"editable": "bottom"}, "field", {"name": "position_ids", "widget": "many2many_tags"}, "field", {"name": "print_filter_ids", "widget": "many2many_tags"}))
                res["arch"] = etree.tostring(doc, encoding="unicode")
    return res

Expected XML Structure inside notebook:

<page string="Teste">

    <field name="customizable_lines_ids">

         <tree editable="bottom">

            <field name="position_ids" widget="many2many_tags"/>

            <field name="print_filter_ids" widget="many2many_tags"/>

        tree>

    field>

page>

Avatar
Discard
Related Posts Replies Views Activity
0
Apr 22
1304
2
Mar 22
1416
0
Nov 23
449
2
Sep 23
652
1
May 23
2871