如何在Odoo中更改工作表标签宽度?

时间:2015-10-20 06:43:42

标签: css odoo-8 odoo

有没有办法在Odoo中更改特定表单的工作表宽度?我创建了一个css文件来更改工作表标签宽度,但所有表单工作表标签的宽度都已更改。我只是想改变某种形式的宽度。可能吗?

3 个答案:

答案 0 :(得分:2)

您可以删除视图中的工作表节点,以将宽度扩展为100%。只需将此功能添加到您的模型中:

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

这是4周前my question的回答

如果你有一个消息框,你可能想用这个来保持布局的顺序

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

答案 1 :(得分:0)

为了在odoo v8上获得相同的结果,我做了一些更改。

@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

答案 2 :(得分:0)

您还可以通过重新定义_renderNode函数来覆盖工作表部件的渲染方式。您可以直接在HTML组件var $sheet = $('<div style='width:100%'>', {class: 'clearfix position-relative o_form_sheet'})中更改样式,或在XML视图$sheet.addClass(node.attrs['class']);中分配定义为属性的自定义类。该新类也必须在CSS代码中定义。

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);
            }
         },
    });    
});