2cadz
(Christophe)
September 4, 2020, 12:57pm
1
Hi,
I’m looking for a way to return a report from a button. I tried the following syntaxes:
@classmethod
@ModelView.button
def print_label(cls, moves):
Label = Pool().get('product.label', type='report')
oext, content, _, _ = Label.execute([x.product.id for x in moves], {})
return ???
There, I don’t know which syntax to use to return the generated report to the client
@classmethod
@ModelView.button
def print_label(cls, moves):
action_reports = Pool().get('ir.action.report').search([
('report_name', '=', 'product.label'),
])[0]
# How to set the IDs ???
return action_reports
with this syntax I don’t know how to indicate the IDs on which the report should be generated ??
Thank you.
dabada83
(Diego Abad)
September 4, 2020, 1:32pm
2
You should use button_action decorator, with the xml_id of report action, similar to this:
@classmethod
@ModelView.button_action('your_module.your_xml_id')
def button(cls, records):
pass
There are samples on core modules:
https://hg.tryton.org/modules/stock_split/file/tip/stock.py#l24
2cadz
(Christophe)
September 4, 2020, 3:14pm
3
Thanks, but this syntax launches a report with in ‘records’ a list of movements, whereas in ‘records’ I would need a list of products (because the report is a report linked to products).
ced
(Cédric Krier)
September 4, 2020, 3:27pm
4
Then you have to pass first by a wizard (button_action being a wizard) that setup the action with the proper ids.
ioanp
(Ioannis Proios)
September 4, 2020, 5:38pm
5
The param “content” have the data from your report.
Save it to a file ex labels.odt and return to client
system
(system)
Closed
October 4, 2020, 5:38pm
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.