跳至内容
菜单
此问题已终结

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.

 

形象
丢弃
相关帖文 回复 查看 活动
2
10月 19
4057
2
10月 19
3511
0
10月 18
3855
2
7月 23
3180
1
7月 23
2153