How to reference a planning type in a plan - odoo

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

Related

Is it normal fields are not updated after installing modules?

I'm developping a module on OpenERP 7.
It is a very simple code : it has only 1 new field (or column) in python file, and an xpath in the xml. I know it works because one time it was succesfully installed
When I try to install/update my module with the module interface, sometimes the field is added/updated to OpenERP, but sometimes no.
I tried to start/stop and restart Openerp before and after installing my module, but I don't know if it has consequences. I don't have errors or useful thing in the logs.
So fields don't add/update but xml update everytime... Does anyone have an idea of what's going on and a solution ?
python code:
# -*- coding: utf-8 -*-
from openerp.osv import fields, osv
class StockPickingIn(osv.osv):
_name = "stock.picking.in"
_inherit = "stock.picking.in"
_columns = {
'adquat_ack_recep': fields.boolean('Accusé de réception'),
}
xml code:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_picking_in_form_adquat" model="ir.ui.view">
<field name="name">stock.picking.in.form.adquat</field>
<field name="model">stock.picking.in</field>
<field name="inherit_id" ref="stock.view_picking_in_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='stock_journal_id']" position="after">
<field name="adquat_ack_recep" />
</xpath>
</field>
</record>
<record id="view_picking_in_tree_adquat" model="ir.ui.view">
<field name="name">stock.picking.in.tree.adquat</field>
<field name="model">stock.picking.in</field>
<field name="inherit_id" ref="stock.view_picking_in_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='state']" position="after">
<field name="adquat_ack_recep" />
</xpath>
</field>
</record>
</data>
</openerp>
I think it works to update fields with Command line -u !
But my other problem is not solved : I dont have empty checkboxes in form view
And in form view i can't have this checkbox checked :
I click on edit, i check it and save : the checkbox come back to empty !
I saw in the database the value is saved as true or false, but it's not displayed on the interface
You should see the following error
ValidateError
Error occurred while validating the field(s) arch: Invalid XML for View Architecture!
Because adquat_ack_recep is defined in stock.picking and you add it to stock.picking.in form.
You need to inherit from stock.picking.in.
_inherit = "stock.picking.in"
Edit:
Add adquat_ack_recep field to both models stock.picking and stock.picking.in (stock.picking.in read method was overitten to read values from stock.picking model). Take a look at fields not saving problem
Problem may arises due two instances running at same time. make sure you run single instance. you can also update module through command line this may solve your issue
refer this link for module updation through command line.

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" />

Odoo 8 Module - adding a new field to the model

I am getting an error adding a new field to an Odoo 8 module. When I comment it out of the view, it works. When it is in, I get the following error:
ParseError: "ValidateError
Field(s) arch failed against a constraint: Invalid view definition
Error details:
Field filedata does not exist
Error context:
View course.form
This is my models.py file:
from openerp import models, fields, api
class Course(models.Model):
_name = 'openacademy.course'
name = fields.Char(string="Title", required=True)
description = fields.Text()
filedata = fields.Binary('File')
And this is an extract from my view file views/openacademy.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="course_form_view">
<field name="name">course.form</field>
<field name="model">openacademy.course</field>
<field name="arch" type="xml">
<form string="Course Form">
<sheet>
<group>
<field name="name"/>
<field name="description"/>
<field name="filedata" />
</group>
</sheet>
</form>
</field>
</record>
....
Any thoughts?
You should try restarting Odoo server as the field probably hasn't been persisted yet due to the binary field misspelling. Try checking the PostgreSQL database directly using PgAdmin or Sql Workbench to check the field is correctly in place.
Regarding your view, everything seems right.
You should update your module through Odoo interface or with the '-u' option of the odoo.py command.
Regards,
Hello dear add like Binary add in camelcase
filedata = fields.Binary('File')
binary field should be capitalized.
First of all define the field properly as said here:
filedata = fields.Binary('File')
And then Uninstall and reinstall your module.
If the problem still occurs,
Create a new database and try again.

Error occured while adding security to a module in openerp

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.