Reputation: 452
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?
Upvotes: 3
Views: 2088
Reputation: 89
You can also overwrite how the sheet component is rendered by redefining _renderNode function. You can change the style directly into the HTML component var $sheet = $('<div style='width:100%'>', {class: 'clearfix position-relative o_form_sheet'})
or assign your custom class defined as an attribute in the XML View $sheet.addClass(node.attrs['class']);
. That new class also has to be defined in the CSS code.
odoo.define('<your_module>.form_renderer', function (require) {
"use strict";
var FormRenderer = require('web.FormRenderer');
FormRenderer.include({
_renderNode: function (node) {
if (node.tag === 'sheet') {
this.has_sheet = true;
var $sheet = $('<div>', {class: 'clearfix position-relative o_form_sheet'});
if(node.attrs['class']){
$sheet.addClass(node.attrs['class']);
}
$sheet.append(node.children.map(this._renderNode.bind(this)));
return $sheet;
} else {
return this._super.apply(this, arguments);
}
},
});
});
Upvotes: 1
Reputation: 9670
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
There is also a community module to achieve a similar result web_sheet_full_width
Upvotes: 2
Reputation: 26748
To have the same result on odoo v8 I have made some changes.
@api.model
def fields_view_get(self, view_id=None, view_type=False, toolbar=False,
submenu=False):
context = self._context
def get_view_id(xid, name):
try:
return self.env['ir.model.data'].xmlid_to_res_id(xid,
raise_if_not_found=True)
except ValueError:
try:
return self.env['ir.ui.view'].search([('name', '=', name)],
limit=1).id
except Exception:
return False # view not found
if not view_type:
view_id = get_view_id('stock_landed_costs.view_stock_landed_cost_tree',
'stock.landed.cost.tree')
view_type = 'tree'
elif view_type == 'form':
view_id = get_view_id('stock_landed_costs.view_stock_landed_cost_form',
'stock.landed.cost.form')
res = super(stock_landed_cost, self).fields_view_get(view_id=view_id,
view_type=view_type,
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
Upvotes: 0