Odoo Help

2

1
7 Answers
2
Jose Vasquez
2016/04/14 10:42

Hi

I spent a bit of code that I use, I worked for odoo9

import xlwt

from xlsxwriter.workbook import Workbook

from cStringIO import StringIO

import base64


def print_excel_report(self, cr, uid, ids, context=None):

    filename= 'detalle_cobranzas.xls'

    workbook= xlwt.Workbook(encoding="UTF-8")

    worksheet= workbook.add_sheet('Detalle de cobranzas')

    style = xlwt.easyxf('font:height 400, bold True, name Arial; align: horiz center, vert center;borders: top medium,right medium,bottom medium,left medium')

    worksheet.write_merge(0,1,0,7,'REPORT IN EXCEL',style)

    fp = StringIO()

    workbook.save(fp)

    export_id = self.pool.get('excel.extended').create(cr, uid, {'excel_file': base64.encodestring(fp.getvalue()), 'file_name': filename}, context=context)

    fp.close()

    return{

        'view_mode': 'form',

'res_id': export_id,

'res_model': 'excel.extended',

'view_type': 'form',

'type': 'ir.actions.act_window',

'context': context,

'target': 'new',

    }


class inventory_excel_extended(models.Model):

_name= "excel.extended"

excel_file = fields.Binary('Dowload report Excel')

file_name = fields.Char('Excel File', size=64)

in xml

        <!-- Add button in your xml form -->
        <button name="print_excel_report" string="Print Excel"/>
        
        <!-- xml excel -->
        <record id="view_excel_form_extended" model="ir.ui.view">
<field name="name">excel.extended.form</field>
<field name="model">excel.extended</field>
<field name="arch" type="xml">
<form string="Excel Report file">
<group>
<field name="excel_file" readonly="1" filename="file_name"/>
<field name="file_name" invisible="1"/>
</group>
</form>
</field>
</record>
<record id="action_excel_form" model="ir.actions.act_window">
<field name="name">Reportes Excel</field>
<field name="view_id" ref="view_excel_form_extended"/>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="res_model">excel.extended</field>
<field name="target">new</field>
</record>

I hope you helps, Greetings.

3 Comments
Jignesh Mehta
2016/04/15 0:14

Thank you so much Jose.

Jignesh Mehta
2016/04/15 1:08

How to add image in the xls report. It gives me error :- Exception: String longer than 32767 characters

Jose Vasquez
2016/04/15 9:12

Hi Jignesh, This could serve you. http://xlsxwriter.readthedocs.org/en/latest/page_setup.html

0
Fernando
2019/04/04 12:45

Hola Jose, use tu código, pero al pulsar el botón que creé no me genera el archivo xls. Podrías ayudarme con esa parte ?. Muchas gracias.

0
Anh Vu
2016/04/14 5:41

Hi,

I prefer to use report_xls -> https://github.com/OCA/reporting-engine

Regards

1 Comment
Odoo Honduras
2016/04/14 20:11

Any user manual to use it??

Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now