3

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?

Ibrahim Rahimi
  • 519
  • 8
  • 31

2 Answers2

4

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.

Charif DZ
  • 14,415
  • 3
  • 21
  • 40
  • I applied above changes but still no effect, also I found this [https://stackoverflow.com/questions/46340375/how-to-remove-implied-ids-from-group-in-odoo]. This solution suggests something different. Which one is correct? in my case non of them work. – Ibrahim Rahimi Sep 24 '19 at 10:29
  • Check if the file is in data in odoo manifest, check if the xml file that loads the data in the original app use no update, if so I will edit my answer to force the Update on the record – Charif DZ Sep 24 '19 at 11:27
  • Actually this code was working but there was something wrong with the sequence of my modules. I find that with lots of debugging. The sequence of depends on menifiest files was causing recalling the original modle and overriding the changes again. – Ibrahim Rahimi Sep 24 '19 at 11:49
1

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>
CZoellner
  • 13,553
  • 3
  • 25
  • 38
  • Do you mean that I just need to add the module name before id? – Ibrahim Rahimi Sep 23 '19 at 06:42
  • Among the other things yes. Don't forget the dependency and don't override every field of that group, if you wish to change just one like `implied_ids`. – CZoellner Sep 23 '19 at 06:47
  • I tried above code, but still, it doesn't affect the group on updating module and even -u all option. – Ibrahim Rahimi Sep 24 '19 at 08:51
  • Yes i didn't read your requirement fully, to delete a relation you have to use "magic number" `3` in this case. I've changed my code. – CZoellner Sep 24 '19 at 08:57
  • This code deletes acs_hms.group_hms_jr_doctor group from implieds_ids of base group or the acs_hms.group_hms_nurse group?. I got confused about it. – Ibrahim Rahimi Sep 24 '19 at 09:01
  • The nurse group. – CZoellner Sep 24 '19 at 09:03
  • I applyed ` ` but still the base group is not overriding. I use this command to update sever: `./odoo-bin --addons-path='addons, ../hms, ../acs-hms, ../12.e' --xmlrpc-port=9000 -d db_hms -u all` – Ibrahim Rahimi Sep 24 '19 at 09:20
  • What do you mean by the base group is not overriding? – CZoellner Sep 24 '19 at 09:38
  • I mean the changes are not applied even after using that command. I even found this[https://stackoverflow.com/questions/46340375/how-to-remove-implied-ids-from-group-in-odoo] and tried this code but still no effect.` ` – Ibrahim Rahimi Sep 24 '19 at 09:41
  • You could also try with `[(6, 0, ref('acs_hms.group_hms_receptionist'))]` which should reset the relations to only one -> receptionist. – CZoellner Sep 24 '19 at 11:05