Odoo Help

Welcome!

This community 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.

0

selection field values in data.xml?

By
mike
on 5/29/13, 2:52 PM 4,164 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'))]"/>
</record>

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

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

hi,

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

thanks

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.

mike
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.

Bista Solutions US, 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?

mike
on 5/29/13, 3:46 PM
0
mike
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>
</record>

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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