我有一个向导,其中有一个 one2many 字段。我在 one2many 的每一行中制作了一个按钮,它调用了我制作的另一个向导。此向导用于修改所选行的某些值。
我的目的是在您单击我的向导的应用 按钮时返回第一个向导,其中包含新的更改。
Example:
The first wizard has a one2many field with three records:
- Product A | 1 ud | Source location X | Dest location Y | Lot A1
- Product B | 2 ud | Source location X | Dest location Y | Lot B1
- Product C | 3 ud | Source location X | Dest location Y | Lot C1
Now, I click on the first line button I made (each line has one), and my wizard is opened. Here I can modify the lot of the first line (the one with the Product A). Imagine I set Lot A0 and click on Apply.
I should return to the parent wizard, and see the same data except for the changes made. So the result will be:
- Product A | 1 ud | Source location X | Dest location Y | Lot A0
- Product B | 2 ud | Source location X | Dest location Y | Lot B1
- Product C | 3 ud | Source location X | Dest location Y | Lot C1
有人知道怎么实现吗?如何保存第一个向导数据?
最佳答案
首先您需要浏览向导的当前记录及其行。然后根据需要写入值。
返回带有向导对象的当前 id。
尝试以下技巧:
#apply button method logic
def apply_data(self, cr, uid, ids, context=None):
if not context:
context = {}
ctx = context.copy()
for wizard in self.browse(cr, uid, ids[0], context=context):
for line in wizard.one2many_field:
line.write({
'field_name': field_value
})
dummy, view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'module_name', 'wizard_form_view_name')
return {
'name':_("Name of your Wizard"),
'view_mode': 'form',
'view_id': view_id,
'view_type': 'form',
'res_id': ids and ids[0] or False,
'res_model': 'wizard.object.name',
'type': 'ir.actions.act_window',
'nodestroy': True,
'target': 'new',
'context': ctx
}
注意:
您还可以更新上下文值。
应用按钮类型必须是对象才能执行方法逻辑。
关于python - 如何在Odoo8中调用其他 Sprite 的 Sprite ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39973410/