one2many包含one2many如何设置值

问题描述 投票:1回答:1

我想直接在onchange值中添加以下模型

数据来自其他模型

我的模特

A类:

_name = 'budget.budget'
main_materials_list = fields.One2many(comodel_name='budget.main.material', inverse_name='budget_id', string=u'A')

@api.onchange('suite_series')
def onchange_suite_series(self):
    self.main_materials_list = self._materialValue()

def _materialValue(self):
    page = []
    for item in self.suite_series.main_material_ids:
        product_ids = []
        data = {
            'product_id':self.main_materials_list.product_ids
        }

        for val in item.product_id:
            product_item = {
                'product_id': val.product_id.id
            }
            product_ids.append((0, 0, product_item)) 

        data.update({'product_ids': product_ids})
        page.append((0, 0, data))
    return page

Class B:
    _name = 'budget.main.material'
    product_ids = fields.One2many(comodel_name='budget.material', inverse_name='main_id', string=u'B')

Class C:
    _name = 'budget.material'
    product_id = fields.Many2one(comodel_name='product.product', string=u'C')

使用上面的方法,然后第二个one2many分配不成功!

odoo odoo-10
1个回答
0
投票

遗憾的是,您无法在onchange事件中执行此操作,这与webclient处理从服务器返回的结果的方式有关。

Odoo忽略在该视图中没有相应字段的每个值,因此当您将值传递给第二个one2many时,他将在该视图中找不到任何字段。

我没试过这个,但我觉得它也行不通。尝试将嵌入式树放在第一个one2many中,将另一个嵌入式树放入第二个one2many字段中,并包含要在onchange事件中传递的所有字段。

为什么我认为它不起作用因为odoo不会在第一个树视图中呈现第二个树视图。如果这不起作用,你需要考虑别的事情。

© www.soinside.com 2019 - 2024. All rights reserved.