您能帮我解决关闭向导的问题吗?
当我添加日期并单击 xlsx 按钮时,我从 xml 创建了一个向导,
生成 xlsx,向导自行关闭。效果很好。
但是当我单击pdf时,pdf生成成功,但向导保持打开状态。
我怎样才能关闭它。
这是我的 xml 代码。
<record id="payment_invoice_wizard_form" model="ir.ui.view">
<field name="name">Invoice Payment Report</field>
<field name="model">invoice.payment_report</field>
<field name="arch" type="xml">
<form string="Invoice Payment Report">
<group>
<field name="start_date"/>
<field name="end_date"/>
<field name="status"/>
</group>
<!-- other fields -->
<footer>
<button name="print_pdf" string="Print" type="object" class="btn-primary"/>
<button name="print_xls" string="Print in XLS" type="object" class="btn-primary"/>
<button string="Cancel" class="btn-default" special="cancel" />
</footer>
</form>
</field>
</record>
在 py 方面,我正在获取所有必要的数据并返回此函数
@api.multi
def print_pdf(self):
#mycode
return self.env.ref('customer_products.pdf_products').report_action(self)
最佳答案
当 Odoo launch the download action of a report它将检查 close_on_report_download
操作属性是否设置为 true
,如果是,它将返回 ir.actions.act_window_close
类型的操作,该操作将关闭向导。
@api.multi
def print_pdf(self):
action = self.env.ref('customer_products.pdf_products').report_action(self)
action.update({'close_on_report_download': True})
return action
编辑:
您可以实现相同的逻辑,覆盖 QWEBActionManager并检查选项是否通过操作定义传递,如果是则关闭窗口。
var ActionManager = require('web.ActionManager');
var session = require('web.session');
ActionManager.include({
ir_actions_report: function (action, options) {
var self = this;
return $.when(this._super.apply(this, arguments), session.is_bound).then(function() {
if (action && action.report_type === 'qweb-pdf' && action.close_on_report_download) {
return self.do_action({ type: 'ir.actions.act_window_close' });
}
});
},
});
关于python-3.x - 单击 odoo 12 中的按钮后关闭向导,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61658546/