3

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>
arleite
  • 101
  • 6

0 Answers0