0
votes

Im trying to make a rule that validates activity owners, are in the tutors pupil list. The problem is fields are in different model apart from the One2Many relation. Both classes here: Activity:

 class Activity(models.Model):
   _name = "proyectosge.activity"

   owner = fields.Many2one('res.users', string="Pupil",default=lambda self: 
   self.env.user,readonly=True)

Usuario:

class Usuario(models.Model):
    _inherit = 'res.users'
    tutor = fields.Many2one('res.users',string="Tutor")
    pupils = fields.One2many('res.users','tutor',string = "Pupils")

And the rule I tried but obviusly not working cause they arent even on the same model:

<!--Tutor only view his pupil activities-->  
        <record model="ir.rule" id="activities_tutor_rule">
            <field name="name">Tutor only see his pupil activities</field>
            <field name="model_id" ref="model_proyectosge_activity"/>
            <field name="groups" eval="[(4, ref('group_tutor'))]"/>
            <field name="domain_force">[('owner','=',pupils)]</field>
            <field name="perm_read" eval="True"/>
            <field name="perm_create" eval="False"/>
            <field name="perm_write" eval="False"/>
            <field name="perm_unlink" eval="False"/>
        </record>
1

1 Answers

0
votes

Try this out if works. I am not 100% sure about this. Let me know if it works. Thanks

<field name="domain_force">[('owner','=',pupils.owner)]</field>