Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
21560 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

hi,

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

thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

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.

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.

Tác giả

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?

Tác giả Câu trả lời hay nhất

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?

Ảnh đại diện
Huỷ bỏ

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 3 15
14913
1
thg 10 25
5186
0
thg 12 24
10164
3
thg 9 24
22523
5
thg 12 24
54405