Odoo Help


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.


How to add data for backtracking relationships

Marco Dieckhoff
on 2/9/13, 5:47 PM 994 views


Let's say have two models, for persons and addresses, where the addresses always belong to a person, and a person may choose one of them as main address.

class person(osv.osv):
    _name = "my.persons"
    _columns = {
         "name": fields.char("Name", size=64, required=True),
         "address_id": fields.many2one("my.addresses" string="Main Address"),
         "addresses_ids": fields.one2many("my.addresses", "person_id", string="All addresses"),

class adress(osv.osv):
    _name = "my.addresses"
    _columns = {
    "name": fields.char("name", size=75),
        "person_id": fields.many2one("my.persons", "Person", required=True),

Now, how do I enter data for this (as demo data / pre-supplied data) to an addon?

Exporting via base module recorder uses some searches like

<field model="my.addresses" name="address_id" search="[('name', '=', 'something')]"/>

and some ref fields like

<field name="address_id" ref="my_addresses_5"/>

The later are even used when they are NOT previously defined in the export of base module recorder, but only afterwards...

It all ends with a long traceback pastebin eXmk93ST (not allowed to post links) and

 File "/home/openerp/openerp/addons/base/ir/ir_model.py", line 647, in _get_id
    raise ValueError('No such external ID currently defined in the system: %s.%s' % (module, xml_id))
ValueError: No such external ID currently defined in the system: my.addresses_something

I tried all this on v6.1 (as I have need of the GTK client and can't upgrade to 7 therefore).

So, how is it done properly?

On 2/10/13, 8:15 AM

You should be able to do that by creating and updating records in the following way:

    <record model="my.persons" id="my_first_person">
      <field name="name">First person</field>

    <record model="my.addresses" id="my_first_address">
      <field name="name">First address</field>
      <field name="person_id" ref="my_first_person"></field>

    <record model="my.addresses" id="my_second_address">
      <field name="name">Second address</field>
      <field name="person_id" ref="my_first_person"></field>

    <record model="my.persons" id="my_first_person">
      <field name="address_id" ref="my_first_address"></field>

Thank you, works well!

on 2/11/13, 4:27 AM

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)


Asked: 2/9/13, 5:47 PM
Seen: 994 times
Last updated: 3/16/15, 8:10 AM