Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged

Hi!

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?

Avatar
Opusti
Best Answer

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>

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

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

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

Thank you, works well!

Related Posts Odgovori Prikazi Aktivnost
2
avg. 15
4950
1
maj 23
2806
1
apr. 23
5802
1
mar. 23
2407
0
dec. 22
3036