如何用python代码获取odoo list视图新增但是尚未保存的数据?

可以在context里面,增加many2one字段,这样后台通过或缺context,可以得到尚未保存到数据库临时数据

如果是嵌套在field里面的关系字段,也可以通过parent关键字获取父项的字段信息

xml code如下

<xpath expr="//page[@name='variants']/field[@name='attribute_line_ids']" position="attributes">
                    <attribute name="context">{'attribute_line_ids':attribute_line_ids}</attribute>
                </xpath>
               
                <xpath expr="//field[@name='value_ids']" position="attributes">
                    <attribute name="options">{'no_create_edit': True,'limit':2}</attribute>
                </xpath>
                <xpath expr="//field[@name='attribute_id']" position="attributes">
                    <attribute name="context">{'attribute_line_ids':parent.attribute_line_ids}</attribute>
                </xpath>          

Python代码如下

#利用上下文获取tree视图里面未保存的记录
        #write_log(str(self._context))
        attr_ids = self._context.get('attribute_line_ids',[])
        valid_attribute_ids = []
        for item in attr_ids:
            #write_log(str(item))
            if item[0] > 0:
                #[4, 25, False]这种格式的记录,是已经存在的属性,其中25是attribute_line_id
                valid_attribute_ids.append(self.env['product.template.attribute.line'].browse(item[1]).attribute_id.id)
            else:
                #记录格式[0, 'virtual_1087', {'product_tmpl_id1': 18, 'attribute_id': 1, 'value_ids': [[6, False, [1]]]}]
                if item[2]['attribute_id']:
                    valid_attribute_ids.append(item[2]['attribute_id'])
        self.set_up_domain(domain,'id','not in',valid_attribute_ids)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值