This question has been flagged
3 Replies
10808 Views

Hi All,

In my project there's a requirement to cut check in batch and print reports in a single click by selecting the list of open supplier invoices. To achieve this I've prepared a wizard and added an option called 'Write check in batch' under 'more' button of the invoice tree view.

 When I select a list of open invoices and choose the above option, a wizard appears for check number entry and it has 2 buttons: 

1. Confirm, 2.Cancel. When user enters the check number and click on confirm it is creating voucher record and validating it as well. Also I'm getting the PDF report instantly as I'm returning a report action at the end of the function.


But my issue is the wizard is not closing and still remains open even after report generation. The Confirm button on the wizard is of type object and I've defined a corresponding method for it where at the end I'm using this:


return self.pool['report'].get_action(cr, uid, [], 'model.report', contect=context) - which generated the PDF.


But my wizard is not closing. Please help me on this. Any help would be appreciated :)


Regards

ASP 

Avatar
Discard

Hi ASP, I see just a typo contect=context, but this may be just copy and paste error. We made a generic print wizard initiated by a button, to be able to send the document to a server printer using base_report_to_printer from a third party named Agile. In Version 7 everything works fine, after printing a preview, i.e. PDF as usual, the wizard closes, in Version 8 it does not. Your project may differ from ours, but it is the same issue. Could you solve your problem meanwhile ?

Did you find the solution?

Best Answer

Hi !

Maybe late but solution is to remove report_type key of the resulting dict.

Example:

action_dict = self.env['report'].get_action('xml_id_of_report')
del action_dict['report_type']
return action_dict

or instead of using the get_action method, you can return this

return {'type': ir.actions.report.xml', 'report_name':'xml_id_of_report'}

Hope this help

Avatar
Discard

First option worked liked a charm, though second option didn't work for me. Still good solution, earned a point from me :).. ThankQ...

However this fails to load the Qweb format.

@deep maybe your Qweb report has an error because I already launch a Qweb-pdf report successfully with this piece of code

Best Answer

in your report action add this:
{
'close_on_report_download':True
}

Example:

def action_confirm(self):   
    vouchers=self.create_vouchers()
r\eport_action=self.env.ref('your_module.your_report_action').report_action(self.ids_to_print)
    report_action['close_on_report_download']=True
    return report_action

and in your form view :
<footer>
<button string="Confirm" class="btn-primary" type="object" name="action_confirm"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>


Avatar
Discard

Works in odoo 12, thank you very much.
Where have you found that, is it in a documentation ?

No it is not in documentation nor it is used anywhere in Odoo, I needed it and I was looking where to add it and it was already there!

Best Answer

Hello,

In your case consider the following example

report_reference = self.env.ref('your_module_name.your_report_action_id').report_action(self, data=datas, config=False)
report_reference.update({'close_on_report_download': True})
return report_reference

It will close the wizard after downloading the report

Regards

Avatar
Discard