This question has been flagged
1 Reply
2713 Views

Hello everyone,

I have an ir.actions.report to print the sales of a POS session with a custom template. So I put a button in the pos.session form to print that report and it work perfectly.


<record id="action_section_closure_report" model="ir.actions.report">
<field name="name">POS Section Closure Report</field>
<field name="model">pos.session</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">pos_extend.report_section_closure_report</field>
<field name="report_file">pos_extend.report_section_closure_report</field>
<field name="print_report_name">'POS Section Closure - %s' % (object.name)</field>
</record>


The problem is I also implemented an option in the Kanban view of the pos.config (Point of Sale), that must print the last closed session sales. The code of that button is like below: 


def _print_last_closure(self):
last_session = self.env['pos.session'].search([
('config_id', 'in', self.ids),
('state', '=', 'closed')
], order='id desc', limit=1)

if last_session:
return self.env.ref('pos_extend.action_section_closure_report').report_action(docids=last_session.ids)

The "_print_last_closure method" is in the pos.config model because it is the method that is trigger from the option that I added in the kanban view of the Point of Sale. But for some reason this method does nothing, when I click on the button it does nothing. Any suggestion?


Avatar
Discard
Author

Hello Akshay Babu, thanks for answering. I have tried your suggestion but it doesn't work either, when I click nothing happens. I think it has to do with context, but I'm not sure.

Best Answer

Hi,

 Try returning

last_session.env.ref('pos_extend.action_section_closure_report').report_action(docids=last_session.ids)
Avatar
Discard