Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3929 Visualizzazioni

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
ott 19
4053
2
ott 19
3508
0
ott 18
3851
2
lug 23
3169
1
lug 23
2145