Ir al contenido
Menú
Se marcó esta pregunta

I am trying to achieve a parent-child object relationship where the child is optional.  Many2one should accomplish this but does not.  When I save the parent, All child records are created despite the "store" and "required" attributes being set to False.

class Parentobject(models.Model):
    _name = 'myapp.parentobject'
    _description = "Parent Object"
    _inherits = {
        'myapp.firstobj':'firstobj_id',
        'myapp.secondobj':'secondobj_id',
  
    }
    firstobj_id = fields.Many2one('myapp.firstobj', required=True, ondelete='cascade')
    secondobj_id = fields.Many2one('myapp.secondobj', store=False, required=False)
With the code above, saving parent (with or without firstobj) causes a record to be created in firstobj and secondobj tables.  This prevents access control from being established differently for parent and both child objects.  All three need "create" for the user who creates the parent, and if there will be any changes to ANY child object, then all child objects need "write" permission.

My access control was set using the Odoo settings (community/docker edition) for groups.

 

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
oct 19
4061
2
oct 19
3513
0
oct 18
3858
2
jul 23
3184
1
jul 23
2160