Odoo:如何显示" Force Availability"通过动态?

时间:2015-09-04 07:30:57

标签: xpath odoo-8

我试图显示"强制可用性" SO转移时动态动态。我做了如下,但没有工作。我该怎么办?

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=True, toolbar=False, submenu=False):
    result = super(StockPicking, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
    if view_type == 'form':
        obj_so_settings = self.pool.get('sale.config.settings')
        so_config_ids = obj_so_settings.search(cr, uid, [], limit=1, order='id DESC', context=context)
        if so_config_ids:
            so_settings = obj_so_settings.browse(cr, uid, so_config_ids[0], context=context)

        if so_settings.remove_force_availability:
            result.update({'arch': result['arch']
                                   + '<xpath expr="//button[@name=\'force_assign\']" position="attributes">'
                                     '<attribute name="invisible">1</attribute></xpath>'})
        else:
            pass

    return result

结果[&#39; arch&#39;]持有整个stock_picking表单数据。

1 个答案:

答案 0 :(得分:1)

最后我明白了

from lxml import etree
def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
    if not context:
        context = {}
    res = super(custom_stock_pick, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)

    if view_type == 'form':
        remove_force_availability = False
        so_settings_obj = self.pool.get('sale.config.settings')
        so_config_ids = so_settings_obj.search(cr, uid, [], limit=1, order='id DESC', context=context)
        if so_config_ids:
            so_settings = so_settings_obj.browse(cr, uid, so_config_ids[0], context=context)
            remove_force_availability = so_settings.group_remove_force_availability

        if remove_force_availability:
            if res['name'] == 'stock.picking.form':
                doc = etree.fromstring(res['arch'])
                nodes = doc.findall(".//*[@name='force_assign']")

                for node in nodes:
                    parent = node.getparent()
                    parent.remove(node)
                    res['arch'] = etree.tostring(doc)
    return res