2

can you please help me regarding close wizard.
i have created a wizard from xml when i add dates and click on xlsx button,
xlsx generated and wizard close it self. it works fine.
but when i click on pdf, pdf generate successfully but wizard remains open.
how can i close it.

here is my code of 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>


on py side i am getting all necessary data and returning this function

    @api.multi
    def print_pdf(self):
        #mycode
        return self.env.ref('customer_products.pdf_products').report_action(self)
kryptonian
  • 97
  • 1
  • 12

1 Answers1

3

When Odoo launch the download action of a report it will check if close_on_report_download action attribute is set to true, if so it will return action of type ir.actions.act_window_close which will close the wizard.

@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

Edit:

You can implement the same logic, override QWEBActionManager and check if the option is passed through the action definition and if yes close the window.

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' });
            }
        });
    },
});
Kenly
  • 24,317
  • 7
  • 44
  • 60
  • this worked fine for odoo version 12 and 13. but this does not works for odoo 11, can you please tell me what is the replacement for action.update({'close_on_report_download': True}) or other alternatives. thanks – kryptonian May 21 '20 at 10:39
  • 1
    The option is not available on Odoo 11 and I did not find a similar option. Check my edit. – Kenly May 21 '20 at 19:57
  • yeah thanks for this one it is really helpful, i have checked JS too but did not find this return statement anywhere .. and, i did not find solution too, i had to use an alternative. i raised UserError instead that says to the user to please reopen the wizard. – kryptonian May 22 '20 at 12:30