Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

generating and saving files as pdf & xls

By
Sri Ramadoss M
on 8/1/13, 8:24 AM 3,307 views

I have a model:

class my_reports(osv.osv):
_name = "my.reports"    
_description = "My reports"
_columns = {
            'pdf_file':fields.binary("PDF File", readonly=True),
            'pdf_file_name':fields.char("PDF File Name", 128, readonly=True),
            'file':fields.binary("Spreadsheet File", readonly=True),
            'file_name':fields.char("Spreadsheet File Name", 128, readonly=True),
        }
my_reports()

Now I would like to generate pdf & spread sheet. I do that with Reporatlab & Xlwt.

import reportlab
from reportlab.pdfgen import canvas

import StringIO
import base64
from xlwt import *
import xlwt

def hello(c):
    c.drawString(100,100,"My pdf")

def generate_payslip_pdf():    
    c = canvas.Canvas("my.pdf")
    hello(c)
    c.showPage()
    c.save()    
    return c

def generate_payslip_xls():    
    wbk = xlwt.Workbook()
    sheet1 = wbk.add_sheet('my sheet')  

    file_data=StringIO.StringIO()
    o=wbk.save(file_data)    
    out=base64.encodestring(file_data.getvalue())
    return out

No I want to download in correct pdf file or xls file, which is not happening.

I am using the my_reports as one2many in another model and is trying to write the generated content to the fields.

Do you have a solution for your problem ?

Gregory Thomas
on 2/19/14, 8:58 AM

did u manage to solve the problem?

ameer ashraf
on 1/4/16, 4:30 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/1/13, 8:24 AM
Seen: 3307 times
Last updated: 3/16/15, 8:10 AM