Setting Odoo default value from XML data file not working - odoo

I'm trying to set the default value for the type field on the product.product model to product. I thought this would be simple using a data file. This is the content of my file:
<odoo>
<function model="ir.values" name="set_default"
eval="('product.product', 'type', 'product')"/>
</odoo>
The module imports without errors, but the default value is not created. It's nowhere to be found. Am I doing something wrong here?
I tried it this way as well, but same result:
<odoo>
<function model="ir.values" name="set_default">
<value>product.product</value>
<value>type</value>
<value>product</value>
</function>
</odoo>

your syntax needs little correction
Try this and it will work :)
<function model="ir.values" name="set_default">
<value eval="str('product.product')"/>
<value eval="str('type')"/>
<value eval="str('product')"/>
</function>
Because each value should be passed individual as per signature sequence.

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

XSLT - set a condition in template to execute only once for sub sequent nodes

I am new to XLST, posting my question after searching for help in this portal.
I have a typical scenario where I need to transform XML into target XML as blocks per status at record node level below.
But the Header <eventName> and <eventdate> should present only once in first block of section in my target file.
Iā€™m using nested for loop on Header in that another loop on record to scan each status code. Once I find status code is !=ā€™00ā€™ then calling a template.
How do I check or set a condition with in template to execute only once for subsequent calls on template?
Tried with a param that var defined in top loop with value assigned position() but it did not work as record level it would remain same.
Please advise a solution.
An example input XML looks like below:
<?xml version="1.0" encoding="utf-8"?>
<n0:example>
<eventName>Managers Event</eventName>
<eventdate>09292016</eventdate>
<header>
<status>01</status>
<SubHead>
<Record>
<status>10</status>
<Service>Food</Service>
</Record>
<Record>
<status>00</status>
<Service>Music</Service>
</Record>
</SubHead>
</header>
<header>
<status>02</status>
<SubHead>
<Record>
<status>11</status>
<Service>Food</Service>
</Record>
<Record>
<status>00</status>
<Service>Music</Service>
</Record>
</SubHead>
</header>
</n0:example>

KeyError every times upgrade Odoo module

I am new to Odoo, I developing a simple module that will add some fields to an existed view. First, I install it to Odoo, it works fine. Then I edit some code, likes add new more field to my module. Now when I upgrade my module with some new code, Odoo display error: KeyError "bla bla".
But if I install my new module to another machine, it works fine.
Did I miss something? How can I fix it.
And, sorry for my bad English, I'm Vietnamese.
Update my code:
my_model.py file:
from openerp.osv import fields, osv
class ij_project_form(osv.osv):
_name = 'project.project'
_inherit = "project.project"
_columns = {
'ij_project_form_id': fields.integer('An integer field', size=11),
'ij_project_form_des': fields.text('A text field')
}
_defaults ={
'ij_project_form_id': 0
}
ij_project_form()
my_view.xml file:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="ij_project_form">
<field name="name">project.project.form</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project" />
<field name="arch" type="xml">
<xpath expr="//field[#name='partner_id']" position="after">
<newline/>
<field name="ij_project_form_id" />
</xpath>
<xpath expr='//page[#string="Project Stages"]' position="after">
<group string="Injection tab" name="sample">
<field name="ij_project_form_des" />
</group>
</xpath>
</field>
</record>
</data>
</openerp>
Here you are inherit the project.project model and this model is in project module so you are first set dependencies in v7,v8 openerp.py and if you work on v9 or v10 than manifest.py
'depends':['project']
1) In odoo the '_name' attribute creates a new table in the backend (i.e., in database). So, when you want to add fields to the existing model (like here 'project.project'), no need to use _name. "_inherit" like above is sufficient.
With the above code it will try to create another table, project_project (which is a base table of odoo, which is already created in database). so, remove the _name in your code and run.
We can use _name along with _inherit, but try to give different name to '_name' attribute. So this conflict wont be raised.
You should update your __openerp__.py file and make sure you place the depends section correctly.
Here, you inherit the project.project module, so you should add this in the __openerp__.py:
'depends': ['project']
This is possibly because here you are inheriting the project module. So in your module's manifest file you have to make depend on the project module
eg:
In your openerp.py file add the following code
'depends': [
'project',
],
Cheers!
This happens with every newcomer in odoo , I also suffered with this "KeyError". Well I changed database by creating new one and Installed all needed modules again. It worked for me .
And about your English ,In Communication words doesn't matter , only understanding is require.
Hi I'm also new too odoo
I encountered same problem KeyError: 'some old model'
The reason is like other answers, due to stale data in the database
I fixed it by removing the records from db with this command
DELETE FROM ir_model WHERE model = 'yourmodule.oldmodelname';

Struts Validation Framework is not working

I have a date field and that should need to allows the dates of pattern MM/dd/yyyy.
In my Struts validation.xml file I have the following code
<field property="newEffectiveDate"
depends="required,date">
<msg name="required"
key="errors.effectiveDate.required" />
<msg name="date" key="errors.date.format" />
<arg0 key="property.effectiveDate" />
<var>
<var-name>datePattern</var-name>
<var-value>MM/dd/yyyy</var-value>
</var>
</field>
Even though I entered the correct format as 4/24/2013, it is throwing an error message saying that the date is in wrong format but when I enter the date as 04-24-2013 it is accepting it.
Any help is greatly appreciated.
date - validates that a field can be converted to a Date. This validator uses java.text.SimpleDateFormat to parse the date and optionally either a datePattern or datePatternStrict variable can be used. If no pattern is specified the default short date format is assumed. The difference between using the datePatternStrict and datePattern variables is that datePatternStrict checks additionally that the input data is the same length as the pattern specified (so for example 1/1/2004 would fail with a pattern of MM/dd/yyyy ).
As taken from: Struts Documentation
Try this instead:
<var><var-value>MM/dd/yyyy</var-value></var>
It seems to be a very common problem with close to 0 answers.
<field property="pwd" depends="required,date">
<arg position="0" key="pswd"/>
<arg position="1" resource="false" key="5"/>
<arg position="0" key="dt"/>
<var>
<var-name>date</var-name>
<var-value>MM/dd/yyyy</var-value>
</var>
</field>
the above code is working fine, so you might want to change <var-name>datePattern</var-name> with <var-name>date</var-name>. Do let me know if it works.

How to display the response format in xml in wcf?

i am getting the output as
<id>1</id>
<name>tt</name>
but i need to display the output as
<record>
<id>1</id>
<name>tt</name>
</record>
<record>
<id>2</id>
<name>te</name>
</record>
how to acheive this?
To structure your response message as you've shown above, create a data contract class named record. Then, in your record class, create properties for id and name. Finally, have your service operation return an array or List of your record class.