python - 如何在Odoo8中调用其他 Sprite 的 Sprite ?

标签 python python-2.7 odoo-8 odoo

我有一个向导,其中有一个 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/

相关文章:

python - 同时运行多个相互通信的 Kivy 应用程序

python - 使用规范化展平三重嵌套 JSON

python - 导入错误 : No module named enum on python 2. 7

python - 如何从 odoo 8 中的另一个函数字段定义 one2many 字段?

odoo - 停止在 odoo 中的特定模型中创建邮件消息和关注者

python - 得到一系列列表的笛卡尔积?

python - Python 中有 Vector3 类型吗?

odoo - 我想修改上下文帐户发票

python - Python open(file)的类型是什么

python - 是否可以使用 pyodide 的 wasm 在浏览器中构建 python wheel?