Search code examples
cssodoo-8odoo

How to change the sheet tag width in Odoo?


Is there a way to change the sheet width for a specific form in Odoo? I've created a css file to change the sheet tag width but all the form sheet tags width had been changed. I just want to change the width for a certain form. Is it possible?


Solution

  • You can delete the sheet node in your view in order to expand the width to the 100%. Just add this function to your model:

    from lxml import etree
    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
        res = models.Model.fields_view_get(self, cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
        if view_type == 'form':
            doc = etree.XML(res['arch'])
            for sheet in doc.xpath("//sheet"):
                parent = sheet.getparent()
            for child in sheet:
                parent.append(child)
            parent.remove(sheet)
            res['arch'] = etree.tostring(doc)
        return res
    

    That was the answer of my question 4 weeks ago

    And if you have a message box, you may want to use this one to keep the order of the layout

    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
        """ Remove the sheet node keeping the elements inside """
        res = models.Model.fields_view_get(self, cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
        if view_type == 'form':
            doc = etree.XML(res['arch'])
            for sheet in doc.xpath("//sheet"):
                for oe_chatter in doc.xpath("//div[@class='oe_chatter']"):
                    sheet.append(oe_chatter)
                parent = sheet.getparent()
            for child in sheet:
                parent.append(child)
            parent.remove(sheet)
            res['arch'] = etree.tostring(doc)
        return res
    

    Update

    There is also a community module to achieve a similar result web_sheet_full_width