Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 拆下';创建和编辑';从多个字段(批次id)中选择类型';离任';使用字段\视图\获取方法_Python_Openerp - Fatal编程技术网

Python 拆下';创建和编辑';从多个字段(批次id)中选择类型';离任';使用字段\视图\获取方法

Python 拆下';创建和编辑';从多个字段(批次id)中选择类型';离任';使用字段\视图\获取方法,python,openerp,Python,Openerp,当“类型”为“传出”(对于交货-销售订单)时,是否有办法删除多个字段(批次id)中的“创建和编辑” 编辑: 已修改: @api.model def fields_view_get(self, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): res = super(stock_transfer_details, self).fields_view_get(view_id=view_id

当“类型”为“传出”(对于交货-销售订单)时,是否有办法删除多个字段(批次id)中的“创建和编辑”

编辑:

已修改:

@api.model
def fields_view_get(self, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    res = super(stock_transfer_details, self).fields_view_get(view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
    #codes here

            if view_type == 'form' and is_outgoing == 'outgoing':
               doc = etree.XML(res['arch'])
               for node in doc.xpath("//field[@name='lot_id']"):
                  node.set('no_create', "true")
                  node.set('no_create_edit', "true")
                  setup_modifiers(node, res['fields']['lot_id'])
            res['arch'] = etree.tostring(doc)
    return res
<field name="field_name" options="{'no_quick_create': True, 'no_create_edit' : True}"/>
股票转让\u details.xml(原件)


输入转账明细
股票转让详情
设置产品和源程序包意味着将获取该产品
包装外。
....
仍然不起作用。如何在树状视图中找到
lot\u id
字段?

试试这个

<field name="many2one field name" options="{'no_create': True}"/>

我要做的是在调用表单时(例如,在操作中)更改模型的上下文,传递类型(传入/传出),然后覆盖字段\u view\u get,以便修改字段lot\u id,添加选项属性@user00000341,仅当类型为“传出”时

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    res = super(material_paper, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
    type = context.get('type', False)
    if view_type == 'form' and type == 'outgoing':
        doc = etree.XML(res['fields']['item_ids']['views']['tree']['arch'])
        update = False
        for field in doc.xpath("//field[@name='lot_id']"):
            field.attrib['options'] = "{'no_create_edit': True}"
            update = True
        if update:
            res['fields']['item_ids']['views']['tree']['arch'] = etree.tostring(doc)
    return res
manyOne小部件(默认)

选项:可用于此小部件的其他可能选项

  • 无快速创建-删除创建和编辑。。。选择权
  • 无创建编辑-删除创建“foo”选项
  • 无创建-无快速创建和无创建编辑组合
  • 无打开-在读取模式下:不作为链接渲染
示例:

@api.model
def fields_view_get(self, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    res = super(stock_transfer_details, self).fields_view_get(view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
    #codes here

            if view_type == 'form' and is_outgoing == 'outgoing':
               doc = etree.XML(res['arch'])
               for node in doc.xpath("//field[@name='lot_id']"):
                  node.set('no_create', "true")
                  node.set('no_create_edit', "true")
                  setup_modifiers(node, res['fields']['lot_id'])
            res['arch'] = etree.tostring(doc)
    return res
<field name="field_name" options="{'no_quick_create': True, 'no_create_edit' : True}"/>

你可以从


Alessandro Ruffolo建议了正确的方法,你可以遵循它。

我知道这是一个老问题,但Alessandro的答案虽然正确,但并不能真正解释这里的问题

Fields view get是一种方法,它将以树的形式一次获取几乎所有可能的视图。问题是,当您检查返回的
字段的
拱门
时,您将看到
项目ID
是一个简单的字段,没有附加到它的树视图

原因是所有子视图都插入到返回值的
字段
属性中各自的字段中。这也是一种递归方法,因此每个子字段都可以附加任意数量的子视图


Allessandro的答案失败的原因之一是视图已经加载到树中的其他地方。查看
res['fields']['item_id']['views']['tree']['arch']
时应该可以正常工作。在更复杂的情况下,该视图可能以前已加载到其他地方。在这种情况下,您必须检查所有字段/视图/树子树,以更改与要使用lxml扩展的字段相匹配的任何字段。

对于哪个版本的Odoo,您面临问题或需要解决方案?请尝试调试代码。在for处放置一个断点,查看res['arch']的内容。如果它不包含字段lot\u id,则视图有问题,而代码没有问题。您好,先生,当我尝试调试它时,没有lot\u id。只有表单字符串出现。仅供参考,字段lot_id位于表单视图之后的树状视图中,这有关系吗?上面是我继承的xml代码(原始)和xml。所以,问题是lot_id字段在树中,因此它不直接在res['arch']中:如果您进入字段_view_get进行调试,您将能够在res对象中看到json结构(但不在'arch'中)。我不能告诉你正确的结构,因为今天我很想家,因此我无法在工作中检查我使用的源代码,但我使用了同样的机制,它在几周前对我有效。像你在年那样破坏你的问题是不合适的。很多人都在努力帮助你。这样对待他们是不礼貌的。(之前的一些编辑也是可疑的;我认为第5版可能是这个问题的最佳版本——但我不确定,否则我会退后。)在传递传入和传出产品时,两者使用相同的视图。因此,如果这样做,传入的也会受到影响。嗨,试试这一个选项=“{'no_create':[('type','=','outgoing')]}”可能是这样的我!你能给我举个例子吗?我不熟悉fields\u view\u Getts谢谢您的帮助,先生,但我对这一点仍然有问题。