Reputation: 11
I would like to print a report from wizard. In this wizard I recover the order selected and call to report_action function with the orders selected.
The problem is that I don't know how to send the orders to this function. This is the code:
def _get_default_orders(self):
return self.env['sale.order'].browse(self.env.context.get('active_ids'))
order_ids = fields.Many2many('sale.order', string='Orders', default=_get_default_orders)
@api.multi
def processed_orders(self):
list = []
for orders in self:
if orders.order_ids:
list.append(orders)
datas = {
'ids': list,
'model': 'sale.order',
}
return self.env.ref('aloha_reports_templates.custom_report_sale_order').sudo().report_action(self, data=datas)
Odoo generate an error because I don't send properly the parameters to the report_action.
Can someone help me?
Thanks
Upvotes: 1
Views: 742
Reputation: 1315
As per your example first, in your system, there is must be aloha_reports_templates.custom_report_sale_order action available for the report.
Let me show you an example from odoo 11 community code File: account/models/account_invoice.py method(invoice_print)
@api.multi
def invoice_print(self):
""" Print the invoice and mark it as sent, so that we can see more
easily the next step of the workflow
"""
self.ensure_one()
self.sent = True
if self.user_has_groups('account.group_account_invoice'):
return self.env.ref('account.account_invoices').report_action(self)
else:
return self.env.ref('account.account_invoices_without_payment').report_action(self)
As per above code in odoo 11 community there is already account_invoices report action already created as below (account/views/account_report.xml).
<report
id="account_invoices"
model="account.invoice"
string="Invoices"
report_type="qweb-pdf"
name="account.report_invoice_with_payments"
file="account.report_invoice_with_payments"
attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
print_report_name="(object._get_printed_report_name())"
groups="account.group_account_invoice"
/>
Hope this helps!
Upvotes: 1