Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet

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
Verwerfen
Beste Antwort

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
Verwerfen
Autor

Thank you, works well!

Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Aug. 15
4850
1
Mai 23
2645
1
Apr. 23
5630
1
März 23
2222
0
Dez. 22
2864