允许门户网站用户访问功能或导航到odoo 12页面

问题描述

我已经在odoo 12中创建了一个模块,该模块允许门户网站用户管理其时间表。
从控制器的模块的所有可用功能中,我使用了sudo(),以便门户用户不会遇到任何访问权限问题。
在创建新的时间表控制器时,直接调用create()函数,在删除控制器时,调用unlink(),但是当用户想要编辑时间表时,我将用户重定向到该页面上的另一个页面,编辑表单,但是当门户网站用户导航到该页面时,它显示403禁止错误消息。
仅当我创建一个新的门户网站用户时,该问题才会发生,它允许已经在odoo中的Joel Willis。
我也已经在该编辑时间表模板中添加sudo(),但是它不起作用。
像这样..

class EditTimesheet(http.Controller):

    @http.route(['/edit_timesheet/<model("account.analytic.line"):timesheet>'],type='http',auth="public",website=True)
    def _edit_timesheet(self,timesheet,category='',search='',**kwargs):
        self.sudo().edit_timesheet(timesheet,**kwargs)

    def edit_timesheet(self,**kwargs):
        return request.render("timesheet_module.edit_timesheet",{'timesheet':timesheet.sudo()})

记录器中的错误
Traceback (most recent call last):
  File "/home/milan/workspace/odoo/odoo12/odoo/api.py",line 1049,in get
    value = self._data[key][field][record._ids[0]]
KeyError: 6

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "/home/milan/workspace/odoo/odoo12/odoo/fields.py",line 1012,in __get__
    value = record.env.cache.get(record,self)
  File "/home/milan/workspace/odoo/odoo12/odoo/api.py",line 1051,in get
    raise CacheMiss(record,field)
odoo.exceptions.CacheMiss: ('account.analytic.line(6,).display_name',None)

odoo.exceptions.AccessError: ('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: Analytic Line,Operation: read) - (Records: [6],User: 8)',None)

解决方法

当您在路由中使用 <model("account.analytic.line"):timesheet> 时,我相信它会在路由被命中时检查模型/登录用户的权限。因此,它甚至在您进入 sudo 调用之前就抛出错误。我建议改用 accout.analytic.line id(确保你只传入 id)并将你的 2 条路线合并成 1 条这样的......

@http.route(['/edit_timesheet/<int:timesheet_id>'],type='http',auth="public",website=True)
    def edit_timesheet(self,timesheet_id,category='',search='',**kwargs):
        timsheet = env['account.analytic.line'].sudo().browse(timesheet_id)
        return request.render("timesheet_module.edit_timesheet",{'timesheet':timesheet})