Reputation: 539
I need to override an existing group in a custom module and change just it's implied_ids
field in another custom module. I tried to use the same code in my module with the changes in implied_ids
but I had bellow error. Then I tried to use inherit_id field but is raised duplicate id error again. Bellow is the original group in a custom module:
<record id="group_hms_jr_doctor" model="res.groups">
<field name="name">Jr Doctor</field>
<field name="category_id" ref="module_category_hms"/>
<field name="implied_ids" eval="[(4, ref('acs_hms.group_hms_nurse')),(4, ref('acs_hms.group_hms_receptionist'))]"/>
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>
and I want to just remove (4, ref('acs_hms.group_hms_receptionist'))
section from it. I tried bellow code, but this errors raises.
odoo.tools.convert.ParseError: "duplicate key value violates unique constraint "res_groups_name_uniq"
DETAIL: Key (category_id, name)=(68, Jr Doctor) already exists.
" while parsing /home/ibrahim/workspace/odoo/hms/nl_hms/security/security.xml:5, near
<record id="group_hms_jr_doctor_inherited" model="res.groups">
<field name="name">Jr Doctor</field>
<field name="inherit_id" ref="acs_hms.group_hms_jr_doctor"/>
<field name="category_id" ref="acs_hms.module_category_hms"/>
<field name="implied_ids" eval="[(4, ref('acs_hms.group_hms_nurse'))]"/>
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>
How can I override any existing groups and changes it?
Upvotes: 3
Views: 2562
Reputation: 14721
To update an existing records you should give the full XML-ID of that records (include the name of app), and to remove an item from many2many field use 3 command
, this will remove the item from x2many
field but doesn't delete it from the database:
<record id="acs_hms.group_hms_jr_doctor" model="res.groups">
<field name="implied_ids" eval="[(3, ref('acs_hms.group_hms_receptionist'))]"/>
</group>
what will happen here is Odoo will call write
on res.groups
and 4
command is used to add record to x2many
field this will not effect the field at all because the record all ready exist.
Upvotes: 4
Reputation: 14768
You have to set the other custom module as dependency in your custom module and then just "override" the values in need by using the full external ID in record
node.
<record id="acs_hms.group_hms_jr_doctor" model="res.groups">
<field name="implied_ids" eval="[(3, ref('acs_hms.group_hms_nurse'))]"/>
</group>
Upvotes: 1