Odoo Help

0

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

By
Anders Wallenquist
on 1/15/16, 6:40 AM 1,574 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')]"/>
</record>





 

0
Jean-Charles Drubay
On 12/25/16, 10:09 PM

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.

Register

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)

Stats

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