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

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?

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

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>
Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you, works well!

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 15
4856
1
thg 5 23
2649
1
thg 4 23
5644
1
thg 3 23
2239
0
thg 12 22
2870