隐藏字段表单fields_view_get

时间:2013-12-05 10:26:58

标签: openerp

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): 

    #override of fields_view_get in order to change the label of the process button and the separator accordingly to the shipping type 

    if context is None: context={} 

    res = super(stock_partial_picking, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu) type = context.get('default_type', False) 

    if type: doc = etree.XML(res['arch']) 
        for node in doc.xpath("//button[@name='do_partial']"): 
             if type == 'in': 
                 node.set('string', _('_Receive')) 
             elif type == 'out': 
                 node.set('string', _('_Deliver'))

我想隐藏qty,expire_date字段


    for node in doc.xpath("//separator[@name='product_separator']"):
        if type == 'in':
            node.set('string', _('Receive Products'))
        elif type == 'out':
            node.set('string', _('Deliver Products'))
    res['arch'] = etree.tostring(doc)
return res

3 个答案:

答案 0 :(得分:0)

设置"invisible" = "1"

for node in doc.xpath("//separator[@name='product_separator']"):
        if type == 'in':
            node.set('string', _('Receive Products'))
            node.set('invisible', '1')
        elif type == 'out':
            node.set('string', _('Deliver Products'))
    res['arch'] = etree.tostring(doc)
return res

答案 1 :(得分:0)

您可以将文件隐藏在与xml视图类似的mannar中,但必须使用像attrs这样的修改属性。 无论如何,结果让它像这样:

<field name="fieldname" modifiers={'invisible': True} />

(根据我的经验,如果我想要一个可见度的条件,而不是在fields_view_get中工作)

答案 2 :(得分:0)

试试这个:

要从表单视图中隐藏字段:使用fields_view_get函数

doc = etree.XML(res['arch'])
if show_hp_status: 
    for node in doc.xpath("//field[@name='status_1']"):
        #use either 'invisible' or node.remove
        node.set('invisible', '1')
        doc.remove(node)
else:
    for node in doc.xpath("//field[@name='status_2']"):
        #use either 'invisible' or node.remove
        node.set('invisible', '1')
        doc.remove(node)

res['arch'] = etree.tostring(doc)