# Return a report from a button

**URL:** <https://discuss.tryton.org/t/return-a-report-from-a-button/3185>\
**Category:** Developer\
**Created:** [September 4, 2020, 12:57pm UTC](https://discuss.tryton.org/t/return-a-report-from-a-button/3185 "2020-09-04T12:57:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![2cadz](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/2cadz/32/130_2.png) [@2cadz](https://discuss.tryton.org/u/2cadz)\
**Post date:** [September 4, 2020, 12:57pm UTC](https://discuss.tryton.org/t/return-a-report-from-a-button/3185/1 "2020-09-04T12:57:20Z")

</div>

Hi,

I’m looking for a way to return a report from a button. I tried the following syntaxes:

```auto
@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

```auto
@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.

---

<div class="post-metadata">

**Author:** ![dabada83](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/dabada83/32/67_2.png) [@dabada83](https://discuss.tryton.org/u/dabada83)\
**Post date:** [September 4, 2020, 1:32pm UTC](https://discuss.tryton.org/t/return-a-report-from-a-button/3185/2 "2020-09-04T13:32:37Z")

</div>

You should use button\_action decorator, with the xml\_id of report action, similar to this:

```python

@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](https://hg.tryton.org/modules/stock_split/file/tip/stock.py#l24)

---

<div class="post-metadata">

**Author:** ![2cadz](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/2cadz/32/130_2.png) [@2cadz](https://discuss.tryton.org/u/2cadz)\
**Post date:** [September 4, 2020, 3:14pm UTC](https://discuss.tryton.org/t/return-a-report-from-a-button/3185/3 "2020-09-04T15:14:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [September 4, 2020, 3:27pm UTC](https://discuss.tryton.org/t/return-a-report-from-a-button/3185/4 "2020-09-04T15:27:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ioanp](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ioanp/32/782_2.png) [@ioanp](https://discuss.tryton.org/u/ioanp)\
**Post date:** [September 4, 2020, 5:38pm UTC](https://discuss.tryton.org/t/return-a-report-from-a-button/3185/5 "2020-09-04T17:38:29Z")

</div>

> [@2cadz](#):
>
> There, I don’t know which syntax to use to return the generated report to the client

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

---

<div class="post-metadata">

**Author:** ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)\
**Post date:** [October 4, 2020, 5:38pm UTC](https://discuss.tryton.org/t/return-a-report-from-a-button/3185/6 "2020-10-04T17:38:35Z")

</div>

Closed on October 4, 2020, 5:38pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
