Odoo Help


selection field values in data.xml?

on 5/29/13, 2:52 PM 6,734 views

Is it possible to populate the values of a selection field from the data.xml file? I have been going through the ~data.xml files for various addons looking for an example of this and have found none. Or maybe I have and it wasn't obvious to me. Are there any good examples of this if it is possible?

I just discovered this in crm_lead_data.xml...

<record model="crm.case.section" id="section_sales_department">
    <field name="stage_ids" eval="[ (4, ref('stage_lead1')), (4, ref('stage_lead2')),
                                    (4, ref('stage_lead3')), (4, ref('stage_lead4')),
                                    (4, ref('stage_lead5')), (4, ref('stage_lead6')),
                                    (4, ref('stage_lead7')), (4, ref('stage_lead8'))]"/>

I am trying to understand how the module uses it but it looks like it might be what I am trying to do ....maybe.

Dharmesh Rathod
On 5/29/13, 3:23 PM


Are you going to create records from XML and trying to filling selection field ?


Hi, I want to use data from XML as default values for the selection field. In my case requirements specifies an address field for County but the business area only includes 14 counties in the state. But the business area may expand to include more counties and states. They want to be able to add new Counties to an XML file as needed.

on 5/29/13, 3:35 PM

I think it might be better to define a new model that stores county names. Then you can add new ones via the UI or via XML or via CSV as needed. You can then relate (via a many2one field) this model to the partner so it can be part of the address.

Ray Carnes
on 5/29/13, 3:38 PM

Yes, I agree. After looking how the state and country fields are based on models through many2one it would make sense to incorporate counties the same way. Then when they need to add counties for other states the county and state models can reference one another. However, in bringing across legacy data from an old app there are very many pesky little lookup tables with mostly static data which I don't see a reason to model but yet wouldn't want to hard-code as global constants. Any suggestions for these?

on 5/29/13, 3:46 PM
On 5/29/13, 4:25 PM

Ok Dharmesh and Ray, I think I see the light (in OpenERP colors). I need a model for each of my pesky lookup tables. Then based on the XML snippet I posted above I create the records as found in crm_lead_data.xml e.g.

<!-- Crm stages -->
<record model="crm.case.stage" id="stage_lead1">
    <field name="name">New</field>
    <field eval="1" name="case_default"/>
    <field name="state">draft</field>
    <field eval="'10'" name="probability"/>
    <field eval="'10'" name="sequence"/>
    <field name="type">both</field>

Then implement a "default loader" as in crm.py e.g.

def _get_stage_common(self, cr, uid, context):
    ids = self.pool.get('crm.case.stage').search(cr, uid, [('case_default','=',1)], context=context)
    return ids

_defaults = {
    'active': 1,
    'stage_ids': _get_stage_common,
    'alias_domain': False, # always hide alias during creation

And define the proper column type e.g.

_columns = {
'stage_ids': fields.many2many('crm.case.stage', 'section_stage_rel', 'section_id', 'stage_id', 'Stages'),

And after all this I'll have a field that can hold selectable values which can be updated via the data.xml file. Is this correct?

Country table is already exist into openerp. You can add missing one by xml.

Dharmesh Rathod
on 5/29/13, 11:15 PM

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

0 follower(s)


Asked: 5/29/13, 2:52 PM
Seen: 6734 times
Last updated: 3/16/15, 8:10 AM