Return a report from a button

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.

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

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).

Then you have to pass first by a wizard (button_action being a wizard) that setup the action with the proper ids.

The param “content” have the data from your report.
Save it to a file ex labels.odt and return to client