user3583681
user3583681

Reputation: 49

Odoo 10 Error when generating a xlsx report

I would like export custom report in xlsx. i try below code but when i press button export, it error AccessDenied: Access denied.

odoo.addons.web.controllers.main: An exception occured during an http request
Traceback (most recent call last):
  File "C:\Program Files (x86)\Odoo 10.0\server\odoo\addons\web\controllers\main.py", line 72, in wrap
  File "C:\Program Files (x86)\Odoo 10.0\server\odoo\addons\web\controllers\main.py", line 1480, in index
  File "C:\Program Files (x86)\Odoo 10.0\server\odoo\http.py", line 118, in dispatch_rpc
  File "C:\Program Files (x86)\Odoo 10.0\server\odoo\service\report.py", line 32, in dispatch
  File "C:\Program Files (x86)\Odoo 10.0\server\odoo\service\security.py", line 13, in check
  File "C:\Program Files (x86)\Odoo 10.0\server\odoo\addons\base\res\res_users.py", line 507, in check
AccessDenied: Access denied

Report XML:

<report 
    id="action_report_excel"
    model="account.invoice"
    string="Export to XLSX"
    report_type="xlsx"
    name="module_name.report_name.xlsx"
    file="module_name.report_name.xlsx"
    attachment_use="False"
/>

Python Code:

from report_xlsx.report.report_xlsx import ReportXlsx

class CustomReportXlsx(ReportXlsx):

    def generate_xlsx_report(self, workbook, data, objs):
        for obj in objs:
            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)

CustomReportXlsx('report.module_name.report_name.xlsx', 'account.invoice')

Python Wizard:

def check_report(self):
    data = {}
    return self.env['report'].sudo().get_action(self, 'module_name.report_name.xlsx', data=data)

help me, please

Upvotes: 2

Views: 1502

Answers (2)

Nilmar Shereef
Nilmar Shereef

Reputation: 26

I faced this issue in my odoov10 community after playing with some package configurations related with xlsx and other things. enter image description here

Note that, if this issue is related to a single customized xlsx report, definitely it is related to access levels(Unfortunately, i faced this for all my xls). I can draw my issues and findings as points like below:

  • I couldn't print ANY XLSX file from odoo
  • Getting error box "AccessDenied: Access denied" from odoo for "ALL" my excel reports.
  • Error is raising from "odoo\addons\base\res\res_users.py" line number 503 (May little vary based on your odoo clone.) and the function is named "def check(cls, db, uid, passwd):"
  • When I check some work arrounds, I got that the argument "passwd" is getting "False" , which leads to this access denied error.

Milky Solution:

Since this issue was in my localhost, and the time was limited, I just passed my admin password into that function manually (Even it is not goof at all).

  • My Code of "odoo\addons\base\res\res_users.py" just altered like below:
  • passwd = '<MY_ADMIN_USER_PASSWORD' if not passwd: # empty passwords disallowed for obvious security reasons raise AccessDenied()

where the function failed with this hard code, I fixed this issue.

Upvotes: 0

Hilar AK
Hilar AK

Reputation: 1675

Add proper access rights for model account.invoice. your current user has no access power to read/write data from account.invoice model

Upvotes: 1

Related Questions