所以我得到了一个用户有活动的模块。问题是每个人都可以编辑它们。我想让只有在活动上注册的学生才能编辑它。 View of teh activity from odoo
Models.py类
# -*- coding: utf-8 -*-
from odoo import models, fields, api, exceptions
class Activity(models.Model):
_name = "proyectosge.activity"
date = fields.Date(default=fields.Date.today)
description = fields.Char(required=True)
duration = fields.Float(digits=(2,1), help="Duration in hours")
remarks = fields.Text(required=True)
owner = fields.Many2one('res.users', string="Pupil",default=lambda self: self.env.user,readonly=True)
@api.constrains('duration')
def _check_duration_not_too_long(self):
for r in self:
if r.duration > 8:
raise exceptions.ValidationError("A activity can´t be more than 8 hours")
@api.constrains('duration')
def _check_duration_not_too_short(self):
for r in self:
if r.duration < 0:
raise exceptions.ValidationError("A activity can´t be less than 0 hours ")
也希望其他用户可以阅读其他学生活动
答案 0 :(得分:1)
用户ir.rule
<record model="ir.rule" id="activities_rule">
<field name="name">User is allowed to update his activities</field>
<field name="model_id" ref="model_proyectosge_activity"/>
<!--
the user is allowed to update or delete the activities that belong
to him.
-->
<field name="domain_force">[('owner','=',user.id)]</field>
<field name="perm_read" eval="Flase"/>
<field name="perm_create" eval="False"/>
<field name="perm_write" eval="True"/>
<field name="perm_unlink" eval="True"/>
</record>