Odoo Help


How to load XML-data to a reference-field?

Anders Wallenquist
on 1/15/16, 6:40 AM 2,167 views

I like to import XML-data ro records with a reference-field:

  <record id="crm_helpdesk_1" model="crm.helpdesk">
        <field eval="1" name="active"/>
         <field name="user_id" ref="base.user_root"/>
         <field name="ref" model="product.product" search="[('name','=','service')]"/>
         <field name="ref2" model="account.account" search="[('code','=','3.1')]"/>



The answer was on launchpad, by Olivier Dony: https://answers.launchpad.net/openobject-server/+question/135245

OpenERP supports this, but the syntax is a bit complex I must say.
If I wanted to set the value of a reference field called "doc_ref" to a partner record with id='partner_record_id', I would use this:
   <field name="doc_ref" eval="'res.partner,%d' % ref('partner_record_id')"/>
or a bit simpler without needing ref(), if the partner record is created in the same XML document:
   <field name="doc_ref" eval="'res.partner,%d' % partner_record_id"/>
The trick is to render the value for the reference field by evaluating python code that gives a "model,id" result.
You can find more examples by looking for this kind of pattern in the OpenERP official addons code.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 1/15/16, 6:40 AM
Seen: 2167 times
Last updated: 12/25/16, 10:09 PM