2
votes

There are records inside openerp/addons/base/res/res_country_data.xml file:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data noupdate="1">
        <record id="ae" model="res.country">
            <field name="name">United Arab Emirates</field>
            <field name="code">ae</field>
            <field file="base/static/img/country_flags/ae.png" name="image" type="base64" />
            <field name="currency_id" ref="AED" />
            <field eval="971" name="phone_code" />
        </record>

I would like to extend this data to include reference to my model data, so I've tried following:

<openerp>
    <data>
        <!-- extend data from country_data.xml -->
        <record id="ae_range" model="res.country"> 
            <field name="ean_range" ref="res.country.ean_range">629</field>
        </record>

        <!-- data for my model country model must be pointing to -->
        <record id="629" model="res.country.ean_range"> 
            <field name="range_start">629</field>
            <field name="range_end">629</field>
            <field name="name">629</field>
        </record>

as suggested in this question, tried common inherit rules, such as:

    <record id="ae_range" model="res.country"> 
        <field name="inherit_id" ref="res.country.ean_range"/>
        ...
    </record>

But each time I get error about missing xmlid. How can I extend already existing data file and populate module with my own data? Maybe I'm doing something terribly wrong, maybe you could suggest how to populate country model with data for my field which had been added during module installation?

EDIT: Class definitions

class InstantProductTemplate(models.Model):
    _name = 'product.template'
    _inherit = 'product.template'

    country_of_origin = fields.Many2one('res.country',
                                        string='Country of origin',
                                        default="_guess_country",
                                        store=True)
class InstantCountryRanges(models.Model):
    _name = 'res.country'
    _inherit = 'res.country'

    ean_range = fields.One2many('res.country.ean_range', 'name')


class InstantCountry(models.Model):
    _name = 'res.country.ean_range'

    name = fields.Char()
    range_start = fields.Integer("Range start")
    range_end = fields.Integer("Range end")

Thank you in advance!

1

1 Answers

1
votes

I would suggest to use better xml IDs for your ranges and then try to get a proper order in your xml file, like:

<openerp>
    <data>
        <!-- use <module>.<xmlid> as correct xml id for referencing -->
        <record id="ean_range_629" model="res.country.ean_range">
            <field name="range_start">629</field>
            <field name="range_end">629</field>
            <field name="name">629</field>
            <field name="country_id" ref="base.ae" />
        </record>
    </data
</openerp>

You need to set the correct xml ID for overriding. For external module records you will have to set the module name and then the xml id. You can find the correct xml ID for example using the debug mode in web client. Open the record (here United Arab Emirates res.country) and under debug drop down chose "View Metadata".

Edit after one2many relation was cleared up:

You will need a many2one field on res.country.ean_range and should edit your one2many on res.country:

# res.country.ean_range
country_id = fields.Many2one(comodel_name='res.country', string="Country")

# res.country
ean_range = fields.One2many('res.country.ean_range', 'country_id')

Now you can use the xml like above! (also edited)