On Friday, September 21, 2018 at 7:07:12 AM UTC, Richard V. wrote:
> 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

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)

-- 
You received this message because you are subscribed to the Google Groups 
"tryton" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton/6542ed7a-5bed-4028-b3d9-ae9e2e6fb40f%40googlegroups.com.

Reply via email to