Error occured while adding security to a module in openerp - odoo

I have created a new module in openerp now I want to give security for the module for that I have created a folder named "security" inside my module folder and created a xml file and ir.model.access.csv file in it.My aim is I want to create two roles for my module one is manager and other is user.
for that I have added the below code in the xml file
<record id="group_mat_mgmt_user" model="res.groups">
<field name="name">User</field>
<field name="category_id" ref="base.module_category_mat_mgmt"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>
<record id="group_mat_mgmt_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id" ref="base.module_category_mat_mgmt"/>
<field name="implied_ids" eval="[(4, ref('group_mat_mgmt_user'))]"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
At the view part I have added like this
<menuitem name="Materials Management" id="menu_mat_mgmt_root"
groups="group_mat_mgmt_manager,group_mat_mgmt_user"
sequence="80"/>
then the permission given at the csv but i got an error like this
File
"C:\OpenErp\openerp\openobject-server\openerp\addons\base\ir\ir_model.py",
line 850, in _get_id raise ValueError('No such external ID
currently defined in the system: %s.%s' % (module, xml_id)) alueError:
No such external ID currently defined in the system:
mat_mgmt.group_mat_mgmt_manager

It looks like you did not add files in openerp.py in well sequence. Are you getting this error from CSV file or from View.xml file ?
You need to check openerp.py file. You may be assign first ir.model.access.csv/module_view.xml and after that, module_security.xml in 'data' attribute. So It will go first checking ir.model.access.csv/module_view.xml and it will not find that group, that you created in security.xml and that will be load after loading ir.model.access.csv/module_view.xml files. You can check it and you need to pass first security.xml and after that, ir.model.access.csv/module_view.xml files in openerp.py.
You can also check by assigning group like this : module_name.GROUP_XML_ID wherever you did assign/use those groups.

Related

How to reference a planning type in a plan

I have a custom odoo module, which extends some existing modules like hr. I want to create an onboarding plan with several predefined tasks in it.
This is my plan acitivity type xml which works at it should. If I update the applikation with this file, I get the desired tasks in the planning types overview.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="hr_plan_activity_type_create_work_contract" model="hr.plan.activity.type">
<field name="activity_type_id" ref="mail.mail_activity_data_todo"/>
<field name="responsible">manager</field>
<field name="summary">Create work contract</field>
<field name="note">Create the work contract for the employee.</field>
</record>
<record id="hr_plan_activity_type_employee_model_in_erp" model="hr.plan.activity.type">
<field name="activity_type_id" ref="mail.mail_activity_data_todo"/>
<field name="responsible">manager</field>
<field name="summary">Employee model in ERP</field>
<field name="note">Complete the employee model in ERP (AHV, Banking, etc.)</field>
</record>
</odoo>
This is my plan.xml which should create a plan with the activity types. The creation of the plan works, but if I reference the activity types, I'll get an error message.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Onboarding -->
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids"
eval="[(6,0,[ref('mycompany.hr_plan_activity_type_employee_model_in_erp')])]"/>
<field name="plan_activity_type_ids"
eval="[(4,0,[ref('mycompany.hr_plan_activity_type_create_work_contract')])]"/>
</record>
</odoo>
In the manifest.py file I first load the plan.activity.type.xml and then the plan.xml so this shouldn't be a problem.
This is the error message I get when I try to upgrade my customized module mycompany:
File "C:\Program Files (x86)\Odoo 13.0e\server\odoo\addons\base\models\ir_model.py", line 1670, in xmlid_lookup
raise ValueError('External ID not found in the system: %s' % xmlid)
odoo.tools.convert.ParseError: "External ID not found in the system: hr.plan.activity.type.hr_plan_activity_type_create_work_contract" while parsing file:/c:/users/myuser/appdata/local/openerp%20s.a/odoo/addons/13.0/mycompany/data/hr/plan.xml:2, near
<odoo>
<!-- Onboarding -->
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids" ref="hr.plan.activity.type.hr_plan_activity_type_create_work_contract"/>
</record>
Does anyone have any ideas?
String identifier stored in ir.model.data, can be used to refer to a record regardless of its database identifier during data imports or export/import roundtrips.
External identifiers are in the form module.id (e.g. account.invoice_graph). From within a module, the module. prefix can be left out.
Sometimes referred to as xml id or xml_id as XML-based Data Files make extensive use of them.
In your example you used model_name.id which probably does not exist in the database, to reference hr_plan_activity_type_create_work_contract record you just need to replace the model name with the module name.
I can see from the log message that the module name is mycompany, try to replace the model name with mycompany:
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids" ref="mycompany.hr_plan_activity_type_create_work_contract"/>
</record>
Update:plan_activity_type_ids is an x2many field
Use the special commands format to set the x2many field values:
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids" eval="[(6,0,[ref('mycompany.hr_plan_activity_type_create_work_contract')])]"/>
</record>
Edit: Only the first one shows up in the GUI
To replaces all existing records in the set by the ids list (using '(6, 0, ids)') you can provide a list of ids inside the triplet. You can find an example in res_partner_demo.xml inside the base module.
Example:
<field name="plan_activity_type_ids" eval="[(6,0,[ref('mycompany.hr_plan_activity_type_employee_model_in_erp'), ref('mycompany.hr_plan_activity_type_create_work_contract')])]"/>
To add an existing record of id id to the set (using (4, id)) you need to provide one id for each triplet. You can find an example in base_groups.xml inside the base module.
Example:
<field name="plan_activity_type_ids" eval="[(4,ref('mycompany.hr_plan_activity_type_employee_model_in_erp')), (4,ref('mycompany.hr_plan_activity_type_create_work_contract'))]"/>
Your ref ids are wrong. hr.plan.activity.type.hr_plan_activity_type_create_work_contract is wrong. You get only one . in a reference. its [<module_name>.]ext_id_of_object.
If you reference the object from the same module you don't have to use module name.part
If you can see the database tables. then things you are referencing are in table ir_model_data
So if the thing you are referencing is in your own model then you cant use just hr_plan_activity_type_create_work_contract as a reference or your_model_name.hr_plan_activity_type_create_work_contract

odoo.tools.convert.ParseError: "External ID not found in the system: project_manage.view_project_turn_over_action" in Odoo12

there are two xml files,the first one has a button,and another is the form view xml.
It should jump to the form view xml,when I click the button.
But I had a mistake:odoo.tools.convert.ParseError: "External ID not found in the system: project_manage.view_test_project_turn_over_action"
(project_manage is the module name and view_test_project_turn_over_action is the action id,both button xml and form view xml are in the module 'project_manage'.)
the button xml:
<button name="%(view_test_project_turn_over_action)d" string="Turn over" type="action"/>
the form view xml:
<record model="ir.actions.act_window" id="view_test_project_turn_over_action">
<field name="name">Turn Over Form</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">test.project.turn.over</field>
<field name="view_mode">form</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_test_project_turn_over_form"/>
<field name="target">new</field>
</record>
It's because sequence of xml files listed in manifest file.
To avoid sequence problem, you can always use external id with module name.
Like
module_name.xml_id
In your case, it would be
%(project_manage.view_test_project_turn_over_action)d
Or you can change sequence of xml file listing in manifest file.

Custom module and creating groups in odoo 10

I'm working with odoo 10 on windows. I've created a new custom module now I want to add some menus of my costum modules to certains users.
I'm new to odoo so my question is can I do that by creating group, associate the menus to my group then add the users to the group (I trid that but it did not work, when I log in with the user I find nothing).
I've search on the web and I found that I need to creat my groups trough ir.model.access.csv (security folder) with this : id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_testmod_test,access_testmod_test,model_testmod_test,,1,1,1,1.
Unfourtunately, I did not quite understand how can I do that and what should I write in some fields.
So can someone please give me a good tutorial that I can use, with examples, witch shows me how to create diffrents groups and adde users to it and add also some of the menus of my custom module to it.
Thank you.
so I tried this code but it did not work with me maybe I did it wrong here what I did : I created a file securuty.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"
Creating group category and group
security/security.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<!-- Creating a Group Category -->
<record id="category_name" model="ir.module.category">
<field name="name">Name</field>
<field name="sequence">1</field>
</record>
<!-- Adding a Group to the Group Category -->
<record id="group_name" model="res.groups">
<field name="name">Group Name</field>
<field name="category_id" ref="category_name"/>
<!-- Adding Rights of existing Groups -->
<field name="implied_ids"
eval="[(4, ref('base.group_system')), (4,ref('base.group_sale_manager'))]"/>
</record>
</data>
</openerp>
Adding a group to an existing menu (base.group_system)
<menuitem name="Name" id="id_name" parent="module.menu_id" action="module.action_id"
groups="base.group_system"/>
security/ir.model.access.csv
Give your group access to your model
access_anything,classname,model_classname,group_id,1,1,1,1
for example (base. is added because model_ir_property is not from the own module)
access_ir_property1,ir_property,base.model_ir_property,your_new_group_id,1,1,1,1
Go to Settings->Groups, select your new group, press "Edit" and add users at page "Users".

Hide fields in odoo9 openerp

I want hide fields for user in odoo 9. For example, hide Deadline in Project > Task module.
Only administrator can see this fields.
Any solution how create group etc. hide_only_admin_see and in field add this line.
<field name="date_deadline" groups="hide_only_admin_see" />
I'm find in source groups="base.group_no_one", groups="base.group_user"
but don't understand is it possible create my own group, when add to fiels that only Manager can see this...
Here is my solution:
https://postimg.org/image/rvxi74f51/
https://postimg.org/image/b87h1dlhv/
https://postimg.org/image/5mzst1wtz/
ID from file add to field etc: groups="export.res_groups_84"
On odoo 8, you forbid access to a field to all users (except configuration permissions) in that way:
<field name="date_deadline" position="attributes">
<attribute name="groups">base.group_system</attribute>
</field>
To create new group of permissions,
on odoo 8, you can create record for new category like:
<record model="ir.module.category" id="xxx">
<field name="name">Name of new category of permissions</field>
<field name="sequence">200</field>
</record>
You can create new records for groups permission on res_groups:
<record model="res.groups" id="hide_only_admin_see">
<field name="category_id" ref="XXXX"/>
<field name="name">Usuario</field>
</record>
On category_id you must write the ir_module_category you are creating / overridiing.
After this, you have to create a line on your ir.model.access.csv to give correct permissions to the model you want, something like:
"access_project.issue","project_issue access","model_project_issue","hide_only_admin_see",1,0,0,0
Finally, go to the line and override like:
<field name="date_deadline" groups="your_custom_module.hide_only_admin_see" />

Creating a new group

I've made a custom module for the warehouse and now I want this module to be available to a new group.
This new group needs to inherit from the stock manager, so it has to have all the rights the stock manager has + access to this new module.
In my xml I defined:
<record id="group_stock_manager_editor" model="res.groups">
<field name="name">Manager Editor</field>
<field name="category_id" ref="base.module_category_warehouse_management"/>
<field name="implied_ids" eval="[(4, ref('group_stock_manager')), (4, ref('account.group_account_user'))]"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
But this doesn't seem to work, how can I achieve this?
Solved it, the problem was that I wanted to inherit the rights from the group_stock_manager from a custom module, so instead of group_stock_manager it had to be stock.group_stock_manager