python - 关闭从方法调用的弹出对话框
问题描述
单击保存按钮后打开弹出对话框时,对话框不会关闭。
我知道我可以添加
<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,
},
}
单击默认操作按钮后,有没有办法关闭弹出的对话框?
解决方案
我想我已经理解你了,但你不能打开你的弹出窗口并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>
推荐阅读
- c# - ChromeDriver 无法在 Windows 7 中运行 Chrome。为什么?
- c# - 命名元组定义中的自定义名称成为默认名称“Item1”和“Item2”
- python - 重新连接后 Mqtt 不向订阅者发送数据
- r - 如何根据单独变量的 bin 识别一个变量的最大值
- testng - fail(String message) 方法在测试中被调用两次时的行为如何
- python - 无法使用 boto3 分页遍历 cloudwatch 上的所有警报
- c++ - 如何在关闭 Qt 控制台应用程序之前运行我的析构函数?
- spf - 什么被认为是 DMARC 失败?
- angular - 尝试为过去的项目安装 Angular 2
- swift - TableView 不会从外部数据源调用 cellsForRow