Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
5667 Lượt xem

Hello Community,

i have created an button to open an wizard an from the wizard i v created another button to print report :

@api.multi

def get_wizard(self):

        return { 'type': 'ir.actions.act_window',

                    'name': 'name,

                    'view_mode': 'form',

                     'view_type': 'form',

                    'res_model': 'report.wizard',

                     'target': 'new' }

but when i click print the window doesn't close , I've tried some solution like ir.actions.act_window_close but i don't launch the wizard , I've also tried to remove report_type from dictionary ,it work partially because the qweb format in not well rendered is there any other solution

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Example:

def action_print(self):
    report_action=self.env.ref('_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 obviously:
<footer>
<button string="Print" class="btn-primary" type="object" name="action_print"/>
<button string="Dismiss" class="btn-secondary" special="cancel"/>
</footer>


Ảnh đại diện
Huỷ bỏ

Hi,
Thanks for your help. Worked on odoo12 CE
But I am wondering if there is not another way of doing this using one line of code.
Something like that
self.env.ref(''_module.your_report_action'')\
.with_context(close_on_report_download=True).report_action(self)
Tried it, didn't worked ^^

Câu trả lời hay nhất

Hello Mohssinn Bouktaib,

Following code snippet will help you to close wizard after printing pdf report

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

Or
You can install this OCA app

https://apps.odoo.com/apps/modules/11.0/web_ir_actions_act_multi/

And try this below code

action_window = {
'type': 'ir.actions.act_window',
'name': 'name',
'res_model': 'report.wizard',
'view_mode': 'form',
'target': 'new',
}

action_close = {'type': 'ir.actions.act_window_close'}

return {
'type': 'ir.actions.act_multi',
'actions': [action_window, action_close]
}

Regards

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

in form view of wizard add footer ...hope it's will be work for you

<footer>                           

<button name="print_report" string="Report Print" type="object" class="oe_highlight"/>                             or                           

<button string="Close" class="oe_link" special="cancel" />

</footer>

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

This problem because the report is not rendered well, if is rendered the wizard will automatically close

Ảnh đại diện
Huỷ bỏ