1
votes

I am trying to create an xlsx report. I tried below code but getting an error:

Traceback (most recent call last): File "/home/shar/Projects/git/odoo/addons/web/controllers/main.py", line 72, in wrap return f(*args, **kwargs) File "/home/shar/Projects/git/odoo/addons/web/controllers/main.py", line 1485, in index request.session.db, request.session.uid, request.session.password, report_id]) File "/home/shar/Projects/git/odoo/odoo/http.py", line 118, in dispatch_rpc result = dispatch(method, params) File "/home/shar/Projects/git/odoo/odoo/service/report.py", line 35, in dispatch res = fn(db, uid, *params) File "/home/shar/Projects/git/odoo/odoo/service/report.py", line 142, in exp_report_get return _check_report(report_id) File "/home/shar/Projects/git/odoo/odoo/service/report.py", line 120, in _check_report raise UserError('%s: %s' % (exc.message, exc.traceback)) UserError: (u"Unknown report type: xlsx: (, NotImplementedError(u'Unknown report type: xlsx',), )", '')

Here is my code:

*.py

# -*- coding: utf-8 -*-
from odoo.addons.report_xlsx.report.report_xlsx import ReportXlsx

class PartnerXlsx(ReportXlsx):

    def generate_xlsx_report(self, workbook, data, partners):
        for obj in partners:
            report_name = obj.name
            # One sheet by partner
            sheet = workbook.add_worksheet(report_name[:31])
            bold = workbook.add_format({'bold': True})
            sheet.write(0, 0, obj.name, bold)


   PartnerXlsx('report.module_name.res.partner.xlsx',
        'res.partner')

*.xml

  <report
      id="partner_xlsx"
      model="res.partner"
      string="Print to XLSX"
      report_type="xlsx"
      name="res.partner.xlsx"
      file="res.partner.xlsx"
      attachment_use="False"
  />
2

2 Answers

0
votes

We don't have a report_type as xlsx format

we have only qweb-pdf,qweb-html,controller

report_type will accept anyone of these (qweb-pdf,qweb-html,controller)

It does not have xlsx as such

Please refer 'ir.actions.report.xml' class for further reference

0
votes

Your code seems right, but remember that all other odoo rules still apply, don't forget to:

  1. Add 'report_xlsx' as a dependency in _openerp_.py manifest
  2. Add your .xml file in data dict inside _openerp_.py manifest ('data': ['report/file.xml'])
  3. Add an __init__.py file with from . import <report_file_name> inside your report folder (where your .py file lies, and desirably, also your xml file, as declared on the manifest).

  4. Add from . import report inside your addon __init__.py file

  5. Update your addon inside odoo app.

Should work after that.