首页 > 解决方案 > 关闭从方法调用的弹出对话框

问题描述

单击保存按钮后打开弹出对话框时,对话框不会关闭。

我知道我可以添加

<footer> 
<button name="save_item" string="Save" type="object" class="oe_highlight" />                 
<button string="Cancel" special="cancel" class="oe_highlight" />
</footer>

save_item在模型中添加将返回True并关闭弹出对话框的方法。

但是,如果我单击网格上的项目(one2many 小部件),它将弹出操作按钮和我的自定义保存/取消按钮。所以按钮会变得多余。

@api.multi
def add_item(self):
    # for record in self:
    return {
        "type": "ir.actions.act_window",
        "name": "Add Item",
        "res_model": "quotation.line",
        "view_type": "form",
        "view_mode": "form",
        "view_id": self.env.ref("prescription.view_quotation_line_form",False).id,
        "target": "new",
        "flags": {"form": {"action_buttons": True}},
        "context": {
                "default_quotation_id": self.id,
                },
    }

单击默认操作按钮后,有没有办法关闭弹出的对话框?

标签: pythonpython-2.7odooodoo-8

解决方案


我想我已经理解你了,但你不能打开你的弹出窗口并action_buttons设置为False只使用你自己的按钮吗?

@api.multi
def add_item(self):
    # for record in self:
    return {
        "type": "ir.actions.act_window",
        "name": "Add Item",
        "res_model": "quotation.line",
        "view_type": "form",
        "view_mode": "form",
        "view_id": self.env.ref("prescription.view_quotation_line_form",False).id,
        "target": "new",
        "flags": {"form": {"action_buttons": False}},
        "context": {
                "default_quotation_id": self.id,
                },
    }

这样,用户只能点击您的按钮,您可以在您的save_item方法中关闭弹出窗口。

编辑

阅读您的评论后,我了解到您希望在编辑记录时摆脱自己的按钮,因为在这种情况下您会看到 4 个按钮,默认按钮和您的按钮。并且在创建时你没有这个问题。我猜您已经创建了自己的添加项目按钮,并且您不允许用户使用默认的 One2many添加元素按钮或类似的东西。试试这个

...
    <field name="id" invisible="1"/>
...
<footer attrs="{'invisible': [('id', '!=', False)]}">
    <button name="save_item" string="Save" type="object" class="oe_highlight" />                 
    <button string="Cancel" special="cancel" class="oe_highlight" />
</footer>

推荐阅读