Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to create Excel report in odoo9 ?

Subscribe

Get notified when there's activity on this post

This question has been flagged
reportexcelodoo9
7 Replies
16116 Views
Avatar
Jignesh Mehta

Hello


I have create one wizard and take a field binary file for store file name.

While opening wizard, the file name appears from default_get method.


My Code is shown below:-

class wiz_print_excel(models.TransientModel):

    _name = 'wiz.print.excel'


    @api.model

    def default_get(self, fields):

        rec = super(wiz_print_excel, self).default_get(fields)

        rec['name'] = 'Presentation.xls'

        rec['file'] = 'file'

    return rec


    file = fields.Binary('File')

    name = fields.Char(string='File Name', size=32)


    @api.multi

    def print_excel_report(self):

        workbook = xlwt.Workbook()

        worksheet = workbook.add_sheet('Sheet 1')

        worksheet.write_merge(0, 0, 2, 8, 'Lucent Jewels Inc', GREEN_TABLE_HEADER)

        workbook.save('/Downloads/Presentation.xls')


Click on Print button of wizard, File saved this location. But when i click on download, errors was occurred.

It gives different error front end as well as back end.


Front End Error:-

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
http://0.0.0.0:8069/web/static/src/js/framework/ajax.js:230
Traceback:
get_file/$target<@http://0.0.0.0:8069/web/static/src/js/framework/ajax.js:230:35
jQuery.event.dispatch@http://0.0.0.0:8069/web/static/lib/jquery/jquery.js:4640:50
jQuery.event.add/elemData.handle@http://0.0.0.0:8069/web/static/lib/jquery/jquery.js:4309:41


Back End Error :-

File "/usr/share/pyshared/werkzeug/serving.py", line 159, in run_wsgi

execute(app)

File "/usr/share/pyshared/werkzeug/serving.py", line 146, in execute

application_iter = app(environ, start_response)

File "/home/jigneshm/workspace/odoo/openerp/service/server.py", line 245, in app

return self.app(e, s)

File "/home/jigneshm/workspace/odoo/openerp/service/wsgi_server.py", line 184, in application

return application_unproxied(environ, start_response)

File "/home/jigneshm/workspace/odoo/openerp/service/wsgi_server.py", line 170, in application_unproxied

result = handler(environ, start_response)

File "/home/jigneshm/workspace/odoo/openerp/http.py", line 1422, in __call__

return self.dispatch(environ, start_response)

File "/home/jigneshm/workspace/odoo/openerp/http.py", line 1396, in __call__

return self.app(environ, start_wrapped)

File "/usr/share/pyshared/werkzeug/wsgi.py", line 411, in __call__

return self.app(environ, start_response)

File "/home/jigneshm/workspace/odoo/openerp/http.py", line 1586, in dispatch

result = ir_http._dispatch()

File "/home/jigneshm/workspace/odoo/addons/web_editor/models/ir_http.py", line 16, in _dispatch

return super(ir_http, self)._dispatch()

File "/home/jigneshm/workspace/odoo/openerp/addons/base/ir/ir_http.py", line 186, in _dispatch

return self._handle_exception(e)

File "/home/jigneshm/workspace/odoo/openerp/addons/base/ir/ir_http.py", line 157, in _handle_exception

return request._handle_exception(exception)

File "/home/jigneshm/workspace/odoo/openerp/http.py", line 743, in _handle_exception

return super(HttpRequest, self)._handle_exception(exception)

File "/home/jigneshm/workspace/odoo/openerp/addons/base/ir/ir_http.py", line 182, in _dispatch

result = request.dispatch()

File "/home/jigneshm/workspace/odoo/openerp/http.py", line 774, in dispatch

r = self._call_function(**self.params)

File "/home/jigneshm/workspace/odoo/openerp/http.py", line 316, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/home/jigneshm/workspace/odoo/openerp/service/model.py", line 118, in wrapper

return f(dbname, *args, **kwargs)

File "/home/jigneshm/workspace/odoo/openerp/http.py", line 309, in checked_call

result = self.endpoint(*a, **kw)

File "/home/jigneshm/workspace/odoo/openerp/http.py", line 893, in __call__

return self.method(*args, **kw)

File "/home/jigneshm/workspace/odoo/openerp/http.py", line 471, in response_wrap

response = f(*args, **kw)

File "/home/jigneshm/key_concept_jc/web/controllers/main.py", line 1049, in content_common

response.set_cookie('fileToken', token)

AttributeError: 'NotFound' object has no attribute 'set_cookie'



Hope you understand my question.

Thanks in advance.

2
Avatar
Discard
Avatar
Jose Vasquez
Best Answer

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.

2
Avatar
Discard
Jignesh Mehta
Author

Thank you so much Jose.

Jignesh Mehta
Author

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

Jose Vasquez

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

Avatar
Fernando
Best Answer

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
Avatar
Discard
Avatar
Vu Nguyen
Best Answer

Hi,

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

Regards

0
Avatar
Discard
Odoo Honduras

Any user manual to use it??

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
In which case we use the attribute _depends in odoo classes ?
report odoo9
Avatar
0
Oct 16
4638
Subtraction in Excell report ODOO 12
report excel Odoo12
Avatar
Avatar
1
Aug 24
3289
How to insert image into the excel report? Solved
report excel images
Avatar
Avatar
Avatar
Avatar
3
Oct 23
14854
How to download .xls file in a single click? Solved
report excel python2.7
Avatar
Avatar
Avatar
Avatar
Avatar
6
Sep 22
29501
Error On Saving Excel Report in Odoo V12c
report excel odooV12
Avatar
Avatar
1
Apr 19
4189
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now