# Printing invoice in proteus

**URL:** <https://discuss.tryton.org/t/printing-invoice-in-proteus/8434>\
**Category:** Developer\
**Created:** [March 22, 2025, 9:47am UTC](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434 "2025-03-22T09:47:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![herve\_02](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/h/7ea924/32.png) [@herve\_02](https://discuss.tryton.org/u/herve_02)\
**Post date:** [March 22, 2025, 9:47am UTC](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434/1 "2025-03-22T09:47:45Z")

</div>

i tried to “print” an invoice in, proteus (getting the file.odt) i search the webn forums, use\_case (i tried to read the code) and i did not success.  
what i did.

```auto
from proteus import config, Model, Wizard, Report
my_config = config.set_trytond('postgresql:///tryton',config_file='/etc/tryton/trytond.conf')
Invoice = Model.get('account.invoice')
invoice,=Invoice.find([('reference', 'like', 'AZT45')])
# invoice is the good invoice i can print the infos
my_report=Report('formo_t.report')
#now i can and i get all infos
type_, data, print_, name = my_report.execute([invoice], {})
#but there is now way i could find to transform thoses data in odt.
#the doc says report.render() I do not know what parameters to give
my_report.render('formo_t..report',my_context)
  Traceback (most recent call last) 
  File "<stdin>", line 1, in <module> 
  AttributeError: 'Report' object has no attribute 'render'*
#it seems that render is not allowed

```

where can i find an exemple that leads to a .odt file ? (the report is odt)

---

<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:** [March 24, 2025, 2:19pm UTC](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434/2 "2025-03-24T14:19:38Z")

</div>

`data` is the rendered content.

---

<div class="post-metadata">

**Author:** ![herve\_02](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/h/7ea924/32.png) [@herve\_02](https://discuss.tryton.org/u/herve_02)\
**Post date:** [March 24, 2025, 2:38pm UTC](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434/3 "2025-03-24T14:38:02Z")

</div>

i tried to save data in a file and it is not a opendocument file.

---

<div class="post-metadata">

**Author:** ![Xavi](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/x/8e8cbc/32.png) [@Xavi](https://discuss.tryton.org/u/Xavi)\
**Post date:** [March 25, 2025, 6:37am UTC](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434/4 "2025-03-25T06:37:30Z")

</div>

If im not wrong the `AttributeError` is raised because [render](https://docs.tryton.org/latest/server/ref/report.html#trytond.report.Report.render) is a `classmethod` and you are calling from an instance of the class instead of the class, also when you call `execute` you have the extension in `type_`.  
If you want to convert the extension maybe you could take a look on [Report.convert](https://docs.tryton.org/latest/server/ref/report.html#trytond.report.Report.render).  
Hope it helps.

---

<div class="post-metadata">

**Author:** ![herve\_02](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/h/7ea924/32.png) [@herve\_02](https://discuss.tryton.org/u/herve_02)\
**Post date:** [March 25, 2025, 7:11am UTC](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434/6 "2025-03-25T07:11:56Z")

</div>

thank you for the link, i tried to understand _that_ thing i allready read before posting, but i did not succed…

```auto
# *classmethod* Report.execute(*ids*, *data* ) 
>>> type_, data, print_, name = my_report.execute([invoice], {}) # << ok

# classmethod Report.render(report, report_context)
# Returns the content of the Report rendered by the templating engine. And add gettext and ngettext to the evaluation context for translatable reports.

#classmethod Report.convert(report, data[, timeout[, retry]])
# Converts the report content data into the format defined by the Report.

>>> Report.convert(my_report,data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'Report' has no attribute 'convert'.
>>> my_report.convert(my_report,data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Report' object has no attribute 'convert'. Did you mean: '_context'?

the same with
# classmethod Report.render(report, report_context)
# Returns the content of the Report rendered by the templating engine. And add gettext and ngettext to the evaluation context for translatable reports.

```

i’ll try to read some code to understand. it would be so simple to have a 10 lines of snippet code. but it seems to be a bad ideas i do not know why.

---

<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:** [March 25, 2025, 8:15am UTC](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434/7 "2025-03-25T08:15:51Z")

</div>

Well it is the format that you have configured.

---

<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:** [March 26, 2025, 5:27pm UTC](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434/8 "2025-03-26T17:27:12Z")

</div>

Closed on March 26, 2025, 5:27pm UTC

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

---

<div class="post-metadata">

**Author:** ![herve\_02](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/h/7ea924/32.png) [@herve\_02](https://discuss.tryton.org/u/herve_02)\
**Post date:** [March 27, 2025, 1:58pm UTC](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434/9 "2025-03-27T13:58:43Z")

</div>

concernant le topic qui a été (à mon sens abusivement fermé car la question posé n’a pas été résolu) ici : [Printing invoice in proteus - #8](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434/8)

bon, peut être que l’on en se comprend pas en anglais. et non le sujet n’est pas résolu.

data est _peut être_ le contenu rendu, **mais** je ne sais pas comment le transformer en fichier .odt.

Est-ce qu’il y a quelque part sur le net un endroit on l’on voit un script qui fait .execute et qui produit un fichier .odt sur le disk ? il manque peut être une manip ou une commande ce serait gentil de la donnée car si je suis la réponse donnée, et que j’enregistre les données sur le disque je n’ai pas un fichier valide.

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [March 27, 2025, 2:43pm UTC](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434/10 "2025-03-27T14:43:46Z")

</div>

You can save the content to a file with the following python code:

```auto
with open(filename, "wb") as file:
        file.write(data)

```

Make sure to change `filename` with the name of the file you want. As tryton already returns the filename and the extension you can constricut it directly. You currently have:

` type_, data, print_, name = my_report.execute([invoice], {})`

So this may be updated to:

```auto
filename = f"{name}.{type_}"
with open(filename, "wb") as file:
        file.write(data)

```

Hope this makes everything clearer and sorry for having an unresolved question closed.

---

<div class="post-metadata">

**Author:** ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)\
**Post date:** [March 27, 2025, 2:44pm UTC](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434/11 "2025-03-27T14:44:15Z")

</div>

```auto
from proteus import config
from proteus import Model, Wizard, Report
my_config = config.set_trytond(
    'tryton_preciball_prod_72_test',
    config_file='/home/mrichez/Workspace/tryton/issues/.trytond.conf')
Invoice = Model.get('account.invoice')
invoice,=Invoice.find([('number', '=', '124100205')])
# invoice is the good invoice i can print the infos
my_report=Report('account.invoice')
#now i can and i get all infos
type_, data, print_, name = my_report.execute([invoice], {})
pdf = bytes(data)
with open("test.pdf", "wb") as f:
    f.write(pdf)

```

This is working for me but my reports are converted in pdf. It should be the same for an odt.

---

<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:** [March 28, 2025, 2:19pm UTC](https://discuss.tryton.org/t/printing-invoice-in-proteus/8434/12 "2025-03-28T14:19:54Z")

</div>

Opened on March 28, 2025, 2:19pm UTC


