我想在xlsx
中导出自定义报告。我尝试下面的代码,但当我按下按钮导出时,它出错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
报告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代码:
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向导:
def check_report(self):
data = {}
return self.env['report'].sudo().get_action(self, 'module_name.report_name.xlsx', data=data)
请帮助我
答案 0 :(得分:1)
为模型 account.invoice 添加适当的访问权限。您当前的用户无权从 account.invoice 模型中读取/写入数据
答案 1 :(得分:0)
在玩了一些与xlsx相关的软件包配置后,我在odoov10社区中遇到了这个问题。
请注意,如果此问题与单个自定义xlsx报告有关,则肯定与访问级别有关(不幸的是,我所有的xls都遇到了此问题)。我可以将我的问题和发现总结如下:
银河解决方案:
由于此问题在我的本地主机中,并且时间有限,所以我只是手动将管理员密码传递给该函数(即使根本不是傻瓜)。
passwd = '<MY_ADMIN_USER_PASSWORD' if not passwd: # empty passwords disallowed for obvious security reasons raise AccessDenied()
该功能因此硬代码而失败,我已修复此问题。