1
votes

I have created a custom module on odoo 10. Now I wanted to create security groups with users where each group have a particular menu of my custom module. I've already asked this question and I followed the answers that I got but I did not get the results (I definitely messed up at some point but I can't see where, this is my first time working with odoo) so I ask again the question. Here's what I did:

I created a file security.xml in my security folder with contain the following

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
   <!-- Creating a Group Category -->        
   <record id="evaluation_subj" model="ir.module.category">
       <field name="name">evaluation subjective</field>
       <field name="sequence">1</field>
   </record>
   <!-- Adding a Group to the Group Category -->
   <record id="group_eval_subj" model="res.groups">
       <field name="name">Groupe Evaluation Subjective</field>
       <field name="evaluation_subj" ref="evaluation subjective"/>
       <!-- Adding Rights of existing Groups -->
       <field name="implied_ids"
              eval="[(4, ref('base.group_system')), 
     (4,ref('base.group_sale_manager'))]"/>
   </record>
  </data>
 </odoo> 

Then in the file pnc_menus.xml (I have a file called pnc_menus.xml where I created all of my menus) I added the groups field to this menu:

<menuitem name="Parties Prenantes" id="pnc_evaluation_stakeholders"
         action="pncevaluation_partieprenante" parent="pnc_documents" sequence="40" groups="base.group_system"/>

Then in csv file of my security folder I added this :

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
eval_group,groupe_evaluation,pnc_evaluation_stakeholders,group_eval_subj,1,1,1,1

When I updated my module I have an error saying "csv file could not be proccessed"

In the log file I have this:
`Exception: Module loading pncevaluation failed: file pncevaluation\security/ir.model.access.csv could not be processed:
 Aucun enregistrement trouv\xe9 pour id externe 'group_eval_subj' dans le champ 'Group'
ERREUR:  une instruction insert ou update sur la table \xab ir_model_access \xbb viole la contrainte de cl\xe9
\xe9trang\xe8re \xab ir_model_access_model_id_fkey \xbb
DETAIL:  La cl\xe9 (model_id)=(559) n'est pas pr\xe9sente dans la table \xab ir_model \xbb.
 File "D:\Odoo 10.0\server\odoo\tools\convert.py", line 898, in convert_csv_import
    raise Exception(_('Module loading %s failed: file %s could not be processed:\n %s') % (module, fname, warning_msg))
Exception: Module loading pncevaluation failed: file pncevaluation\security/ir.model.access.csv could not be processed:
 Aucun enregistrement trouv\xe9 pour id externe 'group_eval_subj' dans le champ 'Group'
ERREUR:  une instruction insert ou update sur la table \xab ir_model_access \xbb viole la contrainte de cl\xe9
\xe9trang\xe8re \xab ir_model_access_model_id_fkey \xbb
DETAIL:  La cl\xe9 (model_id)=(559) n'est pas pr\xe9sente dans la table \xab ir_model \xbb.

The link to my previous question.

3

3 Answers

1
votes

The Group group_sale_manager is moved from base to sales_team in Odoo 10. So change your code like the below

<field name="implied_ids" eval="[(4, ref('base.group_system')), (4,ref('sales_team.group_sale_manager'))]"/>

And do not forget to add sales_team dependency in your module

0
votes

You have given ir.model.access file before security.xml file, that's why it is giving you error

You have to change following points :

  1. In manifest.py file, add security.xml file before ir.model.access.csv file.
  2. In group you have given
  3. In implied_ids, base.group_sale_manager is given, but in Odoo v10, that group is defined in sales_team module, so external id of that group is "sales_team.group_sale_manager".

Here's

<record id="evaluation_subj" model="ir.module.category">
       <field name="name">evaluation subjective</field>
       <field name="sequence">1</field>
   </record>
   <!-- Adding a Group to the Group Category -->
   <record id="group_eval_subj" model="res.groups">
       <field name="name">Groupe Evaluation Subjective</field>
       <field name="evaluation_subj" ref="evaluation_subj"/>
       <!-- Adding Rights of existing Groups -->
       <field name="implied_ids"
              eval="[(4, ref('base.group_system')), 
     (4,ref('sales_team.group_sale_manager'))]"/>
   </record>
0
votes

The logs are clear and mentioning the issue, there's problem with your csv file.

file pncevaluation\security\ir.model.access.csv could not be processed:

No records found for external id 'group_eval_subj' in the 'Group' field

Here are some tips that may can help and solve your issue.

In your __openerp__.py file, make sure that security.xml is loading before the csv file containing the reference of records in it.

Double check ids in the CSV file, they must exactly same as defined in your xml files.

Check your CSV for any error. You can take help of spreadsheet viewer and see whether all columns are properly aligned or not.

Hope this will solve your problem.

PS:

Here's the updated code. With the fix in group record definition. Update your security.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
   <!-- Creating a Group Category -->        
   <record id="evaluation_subj" model="ir.module.category">
       <field name="name">evaluation subjective</field>
       <field name="sequence">1</field>
   </record>

   <!-- Adding a Group to the Group Category -->
   <record id="group_eval_subj" model="res.groups">
       <field name="name">Groupe Evaluation Subjective</field>
       <field name="category_id" ref="evaluation_subj"/>
       <!-- Adding Rights of existing Groups -->
       <field name="implied_ids" eval="[(4, ref('base.group_system')), (4,ref('base.group_sale_manager'))]"/>
   </record>

  </data>
 </odoo> 

Following the answer of sfx, The group sale manager is moved to module sale_team in odoo 10, so you need to change respective line as:

<field name="implied_ids" eval="[(4, ref('base.group_system')), (4,ref('sales_team.group_sale_manager'))]"/>

Thanks to sfx