Generating reports in PDF

95 views
Skip to first unread message

Khurram Shahzad

unread,
Jul 18, 2018, 4:07:52 AM7/18/18
to try...@googlegroups.com
Hi All,

Can I generate reports in PDF format in Tryton?

If not possible (or very difficult), can I render the PDF file as a report. I am able to call a an HTTP Service to get the generated PDF file (as stream) but can not show it as a report from Report Menu.

--
 
Regards,
Khurram.

Cédric Krier

unread,
Jul 18, 2018, 11:30:06 AM7/18/18
to try...@googlegroups.com
On 2018-07-18 13:07, Khurram Shahzad wrote:
> Can I generate reports in PDF format in Tryton?

Yes, you need to have 'soffice' installed (from LibreOffice or
OpenOffice) and you must set the extension of the ir.action.report to
'pdf'.

> If not possible (or very difficult), can I render the PDF file as a report.
> I am able to call a an HTTP Service to get the generated PDF file (as
> stream) but can not show it as a report from Report Menu.

You can override the method 'render' of your Report class. It must
return the bytes of file that you have generated.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

E. Boer

unread,
Jul 19, 2018, 12:15:58 PM7/19/18
to tryton
On Wednesday, 18 July 2018 10:07:52 UTC+2, Khurram Shahzad wrote:
> Hi All,
>
>
> Can I generate reports in PDF format in Tryton?

Yes, like Cedric said, install LibreOffice or Openoffice and go in the client to Administration -> User Interface -> Actions -> Reports. Get the report you want to print to PDF and set "Extension" to "Portable Documment Format". Next time you print that report, it will generate automatically a PDF for you. it's very easy.

It's even possible to create a report and add another PDF as watermark or background to the report. When we send documents to our customers we add our stationary to the report, so it will be exactly the same as the paper version. This takes a bit more of work by creating an new report and do some coding.

Khurram Shahzad

unread,
Jul 20, 2018, 6:35:05 AM7/20/18
to tryton
On Wednesday, July 18, 2018 at 8:30:06 PM UTC+5, Cédric Krier wrote:
> On 2018-07-18 13:07, Khurram Shahzad wrote:
> > Can I generate reports in PDF format in Tryton?
>
> Yes, you need to have 'soffice' installed (from LibreOffice or
> OpenOffice) and you must set the extension of the ir.action.report to
> 'pdf'.

I am working on it and will share the update soon.

>
> > If not possible (or very difficult), can I render the PDF file as a report.
> > I am able to call a an HTTP Service to get the generated PDF file (as
> > stream) but can not show it as a report from Report Menu.
>
> You can override the method 'render' of your Report class. It must
> return the bytes of file that you have generated.
>
Thank you so much. I was able to successfully display the PDF file received from a network service using Report menu. However, I had to add MIMETYPE for PDF in report.py ('pdf': 'application/pdf'). Otherwise, it throws an Exception in the convert method being 'No Such file ..'.

Khurram Shahzad

unread,
Jul 20, 2018, 6:35:08 AM7/20/18
to tryton
On Thursday, July 19, 2018 at 9:15:58 PM UTC+5, E. Boer wrote:
> On Wednesday, 18 July 2018 10:07:52 UTC+2, Khurram Shahzad wrote:
> > Hi All,
> >
> >
> > Can I generate reports in PDF format in Tryton?
>
> Yes, like Cedric said, install LibreOffice or Openoffice and go in the client to Administration -> User Interface -> Actions -> Reports. Get the report you want to print to PDF and set "Extension" to "Portable Documment Format". Next time you print that report, it will generate automatically a PDF for you. it's very easy.
>
> It's even possible to create a report and add another PDF as watermark or background to the report. When we send documents to our customers we add our stationary to the report, so it will be exactly the same as the paper version. This takes a bit more of work by creating an new report and do some coding.

That's a good idea to convert the reports to PDF so as it avoid editing by the end users before printing. I will surely check this feature and will share my feedback here. Thanks for your kind response.

Khurram.

Cédric Krier

unread,
Jul 20, 2018, 6:55:06 AM7/20/18
to tryton
Indeed if you do not need to convert, you should also override 'convert'
method to return (output_format, data) directly.
It is better than modify MIMETYPES because it has other usage.

Khurram Shahzad

unread,
Jul 20, 2018, 2:00:05 PM7/20/18
to tryton
On Friday, July 20, 2018 at 3:55:06 PM UTC+5, Cédric Krier wrote:
> On 2018-07-20 03:30, Khurram Shahzad wrote:
> > On Wednesday, July 18, 2018 at 8:30:06 PM UTC+5, Cédric Krier wrote:
> > > On 2018-07-18 13:07, Khurram Shahzad wrote:
> > > > If not possible (or very difficult), can I render the PDF file as a report.
> > > > I am able to call a an HTTP Service to get the generated PDF file (as
> > > > stream) but can not show it as a report from Report Menu.
> > >
> > > You can override the method 'render' of your Report class. It must
> > > return the bytes of file that you have generated.
> > >
> > Thank you so much. I was able to successfully display the PDF file received from a network service using Report menu. However, I had to add MIMETYPE for PDF in report.py ('pdf': 'application/pdf'). Otherwise, it throws an Exception in the convert method being 'No Such file ..'.
>
> Indeed if you do not need to convert, you should also override 'convert'
> method to return (output_format, data) directly.
> It is better than modify MIMETYPES because it has other usage.
>

True! That's the right way!
Reply all
Reply to author
Forward
0 new messages