How to return a file from an action

62 views
Skip to first unread message

Khurram Shahzad

unread,
Jan 4, 2018, 4:25:06 AM1/4/18
to tryton
Hi,

We have integrated Tryton with BikaLims using BikaLIMS JSON API (https://github.com/bikalims/bika.lims/wiki/BIKA-JSON-API)

For this, our Tryton module connects and retrieves data from BikaLIMS and stores it in database. But, now we have a requirement in which we want to download reports from BikaLims and display them in PDF Viewer.

For example, from my module, I want to send following HTTP request after authentication:

http://172.29.0.6:88/lims/clients/client-1/blood-5406-R01/arreport-15857/at_download/Pdf

As a response, I will receive the HTTP Response containing contents of PDF report.

What is the best way of displaying this PDF file using Tryton?

Should I write an action which does authentication and returns the above-mentioned URL and rest is handled by the Tryton? If so, any reference example please.

Should I write an action which does authentication, writes the contents from HTTP Response to a temporary file which is returned to Tryton for display. If so, any reference example please.

By the way, I could not find some example for Action of Type URL and also there is a 'Web Services' sections in Tryton Documentation which is empty.

Thanking in anticipation.

Khurram.

Cédric Krier

unread,
Jan 4, 2018, 5:20:04 AM1/4/18
to tryton
On 2018-01-03 20:50, Khurram Shahzad wrote:
> Hi,
>
> We have integrated Tryton with BikaLims using BikaLIMS JSON API (https://github.com/bikalims/bika.lims/wiki/BIKA-JSON-API)
>
> For this, our Tryton module connects and retrieves data from BikaLIMS and stores it in database. But, now we have a requirement in which we want to download reports from BikaLims and display them in PDF Viewer.
>
> For example, from my module, I want to send following HTTP request after authentication:
>
> http://172.29.0.6:88/lims/clients/client-1/blood-5406-R01/arreport-15857/at_download/Pdf
>
> As a response, I will receive the HTTP Response containing contents of PDF report.
>
> What is the best way of displaying this PDF file using Tryton?

You have two options:

- return the PDF file as the result of Report.render.

- put the PDF data in a Binary field (may be a Function field) and
display the field on a Model (ModelSQL or ModelView of a wizard).

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

Richard V.

unread,
Sep 21, 2018, 3:07:12 AM9/21/18
to tryton
On Thursday, January 4, 2018 at 4:20:04 AM UTC-6, Cédric Krier wrote:
> You have two options:
>
> - return the PDF file as the result of Report.render.
>
> - put the PDF data in a Binary field (may be a Function field) and
> display the field on a Model (ModelSQL or ModelView of a wizard).
>

I am very interested in doing something very similar, but instead of downloading a PDF, it is an XML file that is created on the fly with some invoice information. Can anyone help me with some sample code on how to do this? I tried Cédric's option #2 using a function field wrapping a binary field and have the function field's getter method return the XML text, but on the view, the field is shown as a file-upload widget with a text saying 0.00 bytes and a button to select the file to be uploaded next to it. It seems that I can't download the XML file.
Many thanks for the help in advanced.

Richard Vong

Markus Bala

unread,
Sep 21, 2018, 3:30:12 AM9/21/18
to tryton
I am using Relatio to do this job, please see my example as below:

from relatorio import Report

class BarcodeLabel(Workflow, ModelSQL, ModelView):

@classmethod
def print_lpn(cls, records):
report = Report(abspath(join(dirname(__file__), 'lpn.odt')),
ODT_MIME)
data = report(records=records).render().getvalue()
file_name = join(dirname(__file__), 'output_basic.odt')
open(file_name, 'wb').write(data)

Sergi Almacellas Abellana

unread,
Sep 21, 2018, 3:57:45 AM9/21/18
to try...@googlegroups.com
If you want to create an XML file you can use the report engine to build
it and show them using the print option of the clients.

This way you don't have to create a wizard to lunch the XML, but just
select the records you want to export as XML.

Hope it helps!


--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Khurram Shahzad

unread,
Sep 21, 2018, 7:01:46 AM9/21/18
to try...@googlegroups.com
Dear,

Have a look at the thread where we discussed and resolved almost same issue:


Best Regards,
Khurram.

Markus Bala

unread,
Sep 21, 2018, 2:29:12 PM9/21/18
to tryton

Richard V.

unread,
Sep 21, 2018, 3:54:12 PM9/21/18
to tryton
Thank you all for the help. I will try each of the suggestion and see which one works best.

Reply all
Reply to author
Forward
0 new messages