Skip to Content
Menu
This question has been flagged
1 Reply
4620 Views
Hello
I am trying to generate an excel report and when generating it odoo displays an access permissions error. The code that gives an error is the following:

PY
book.save(f_out)
f_out.flush()
self.export_file = base64.b64encode(open(f_out.name, "rb").read())
self.export_filename = "Purchases-Analysis.xls"
f_out.close()
generating the following error:

Odoo Server Error
Traceback (most recent call last):
  File "C:\Odoo\Odoo 14\server\odoo\addons\base\models\ir_http.py", line 237, in _dispatch
    result = request.dispatch()
  File "C:\Odoo\Odoo 14\server\odoo\http.py", line 683, in dispatch
    result = self._call_function(**self.params)
  File "C:\Odoo\Odoo 14\server\odoo\http.py", line 359, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "C:\Odoo\Odoo 14\server\odoo\service\model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "C:\Odoo\Odoo 14\server\odoo\http.py", line 347, in checked_call
    result = self.endpoint(*a, **kw)
  File "C:\Odoo\Odoo 14\server\odoo\http.py", line 912, in __call__
    return self.method(*args, **kw)
  File "C:\Odoo\Odoo 14\server\odoo\http.py", line 531, in response_wrap
    response = f(*args, **kw)
  File "C:\Odoo\Odoo 14\server\odoo\addons\web\controllers\main.py", line 1393, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "C:\Odoo\Odoo 14\server\odoo\addons\web\controllers\main.py", line 1381, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "C:\Odoo\Odoo 14\server\odoo\api.py", line 396, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "C:\Odoo\Odoo 14\server\odoo\api.py", line 383, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "c:\odoo\odoo 14\server\custom_addons\andys\andys_purchases_analysis\wizard\purchases_analysis.py", line 290, in action_export
    self.export_file = base64.b64encode(open(f_out.name, "rb").read())
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Odoo\Odoo 14\server\odoo\http.py", line 639, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "C:\Odoo\Odoo 14\server\odoo\http.py", line 315, in _handle_exception
    raise exception.with_traceback(None) from new_cause
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\frx\\AppData\\Local\\Temp\\tmpq09lk748'


I tried to apply the suggestion from the post below with the sudo() command. before the read. But it does not work.

https://www.odoo.com/es_ES/forum/ayuda-1/permissionerror-errno-13-permission-denied-160577

I appreciate the help


Avatar
Discard
Best Answer

Hello Franklin Heber Justiniano Castillo,

Please find code in comment. 

I Hope this will help you. 

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

Can you please try below method to generate an excel report.

PY:
workbook = xlwt.Workbook(encoding="UTF-8")
worksheet = workbook.add_sheet("Sheet")

... Write work sheet ...

fp = BytesIO()
workbook.save(fp)
fp.seek(0)
excel_file = base64.encodebytes(fp.getvalue())
fp.close()
self.write({'excel_file': excel_file})

Related Posts Replies Views Activity
1
May 24
521
0
Oct 21
1292
1
Jan 21
2184
1
Nov 24
1486
1
Nov 24
1195