Skip to Content
Menu
This question has been flagged
1 Reply
1966 Views

When initializing with data, I'm running into what probably is a circular reference or a missing type cast (see code below):
"witness" derives from (is-a) "person". "person" has a one2many-relation to "address". "address" vice versa has a "resident", which is a many2one-relation to "person". I'm forward-declaring eight empty addresses. When initializing "witness", the error is:

"Wrong value for ufodata.address.resident: ufodata.witness(13,)"

My guess is that "resident" expects a "person" type, but gets a "witness" type. But there's no cast operator, isn't it? My underlying business model seems legit to me (I want to initialize with "witness", which IS a "person"), so I expect to find a solution for correct initialization. What am I doing wrong?

Content of data.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!-- FORWARD DECLARATIONS -->
<record id="case_001" model="ufodata.case"/>
<record id="case_002" model="ufodata.case"/>
<record id="case_003" model="ufodata.case"/>

<record id="address_001" model="ufodata.address"/>
<record id="address_002" model="ufodata.address"/>
<record id="address_003" model="ufodata.address"/>
<record id="address_004" model="ufodata.address"/>
<record id="address_005" model="ufodata.address"/>
<record id="address_006" model="ufodata.address"/>
<record id="address_007" model="ufodata.address"/>
<record id="address_008" model="ufodata.address"/>

<record id="witness_001" model="ufodata.witness">
<!-- from ufodata.person -->
<field name="first_name" >Arthur</field>
<field name="middle_name" >C.</field>
<field name="surname" >Clarke</field>
<field name="age" >90</field>
<field name="birthday" >1917-12-16</field>
<field name="obit" >2008-03-19</field>
<field name="gender" >male</field>
<field name="addresses" eval="[(6, 0, [ref('address_004')])]" ></field>
</record>
<record id="witness_002" model="ufodata.witness">
<!-- from ufodata.person -->
<field name="first_name" >Isaac</field>
<field name="middle_name" >J.</field>
<field name="surname" >Asimov</field>
<field name="age" >72</field>
<field name="birthday" >1920-01-02</field>
<field name="obit" >1992-04-06</field>
<field name="gender" >male</field>
<field name="addresses" eval="[(6, 0, [ref('address_005')])]" ></field>
</record>
<record id="witness_003" model="ufodata.witness">
<!-- from ufodata.person -->
<field name="first_name" >Robert</field>
<field name="middle_name" >A.</field>
<field name="surname" >Heinlein</field>
<field name="age" >80</field>
<field name="birthday" >1907-07-07</field>
<field name="obit" >1988-05-08</field>
<field name="gender" >male</field>
<field name="addresses" eval="[(6, 0, [ref('address_006')])]" ></field>
</record>
<record id="witness_004" model="ufodata.witness">
<!-- from ufodata.person -->
<field name="first_name" >Ray</field>
<field name="middle_name" >Douglas</field>
<field name="surname" >Bradbury</field>
<field name="age" >91</field>
<field name="birthday" >1920-08-22</field>
<field name="obit" >2012-06-05</field>
<field name="gender" >male</field>
<field name="addresses" eval="[(6, 0, [ref('address_007')])]" ></field>
</record>
<record id="witness_005" model="ufodata.witness">
<!-- from ufodata.person -->
<field name="first_name" >Philip</field>
<field name="middle_name" >Kindred</field>
<field name="surname" >Dick</field>
<field name="age" >53</field>
<field name="birthday" >1928-12-16</field>
<field name="obit" >1982-03-02</field>
<field name="gender" >male</field>
<field name="addresses" eval="[(6, 0, [ref('address_008')])]" ></field>
</record>

<!-- ADDRESSES -->
<record id="address_001" model="ufodata.address">
<field name="street" >Dagobertstraße</field>
<field name="number" >5</field>
<field name="number_add" ></field>
<field name="zip_code" >98765</field>
<field name="city" >Duckburg</field>
<field name="country_id" >DE</field>
<field name="email" >dagobert@duck.de</field>
<field name="phone_number" >+49 (0) 999 777777</field>
<field name="resident" />
</record>
<record id="address_002" model="ufodata.address">
<field name="street" >Donaldallee</field>
<field name="number" >7</field>
<field name="number_add" ></field>
<field name="zip_code" >98765</field>
<field name="city" >Duckburg</field>
<field name="country_id" >DE</field>
<field name="email" >donald@duck.de</field>
<field name="phone_number" >+49 (0) 999 777778</field>
<field name="resident" />
</record>
<record id="address_003" model="ufodata.address">
<field name="street" >Daisystraße</field>
<field name="number" >15</field>
<field name="number_add" ></field>
<field name="zip_code" >98765</field>
<field name="city" >Duckburg</field>
<field name="country_id" >DE</field>
<field name="email" >daisy@duck.de</field>
<field name="phone_number" >+49 (0) 999 777779</field>
<field name="resident" />
</record>
<record id="address_004" model="ufodata.address">
<field name="street" >Stalinallee</field>
<field name="number" >15</field>
<field name="number_add" >B</field>
<field name="zip_code" >10001</field>
<field name="city" >Rostberlin</field>
<field name="country_id" >DE</field>
<field name="email" >arthur@cclarke.de</field>
<field name="phone_number" >+49 (0) 999 999999</field>
<field name="resident" ref="witness_001" />
</record>
<record id="address_005" model="ufodata.address">
<field name="street" >Kurfürstendamm</field>
<field name="number" >22</field>
<field name="number_add" >A</field>
<field name="zip_code" >10002</field>
<field name="city" >Restberlin</field>
<field name="country_id" >DE</field>
<field name="email" >isaac@asimov.de</field>
<field name="phone_number" >+49 (0) 999 999999</field>
<field name="resident" ref="witness_002" />
</record>
<record id="address_006" model="ufodata.address">
<field name="street" >Unter den Blinden</field>
<field name="number" >1</field>
<field name="number_add" ></field>
<field name="zip_code" >10002</field>
<field name="city" >Rostberlin</field>
<field name="country_id" >DE</field>
<field name="email" >robert@aheinlein.de</field>
<field name="phone_number" >+49 (0) 999 999999</field>
<field name="resident" ref="witness_003" />
</record>
<record id="address_007" model="ufodata.address">
<field name="street" >Unter den Blinden</field>
<field name="number" >2</field>
<field name="number_add" ></field>
<field name="zip_code" >10002</field>
<field name="city" >Rostberlin</field>
<field name="country_id" >DE</field>
<field name="email" >ray@bradbury.de</field>
<field name="phone_number" >+49 (0) 999 999999</field>
<field name="resident" ref="witness_004" />
</record>
<record id="address_008" model="ufodata.address">
<field name="street" >Unter den Blinden</field>
<field name="number" >3</field>
<field name="number_add" ></field>
<field name="zip_code" >10002</field>
<field name="city" >Rostberlin</field>
<field name="country_id" >DE</field>
<field name="email" >philip@kdick.de</field>
<field name="phone_number" >+49 (0) 999 999999</field>
<field name="resident" ref="witness_005" />
</record>

<!-- SIGHTINGS -->
<record id="sighting_001" model="ufodata.sighting">
<field name="identifier" >20200102 A-S01</field>
<field name="description" >QWERTZ</field>
<field name="begin" >2020-01-02 17:50:00</field>
<field name="end" >2020-01-02 17:50:00</field>
<field name="location">12623 Berlin</field>
<field name="case" ref="case_001"></field>
<field name="witnesses" eval="[(6, 0, [ref('witness_001')])]"></field>
</record>
<record id="sighting_002" model="ufodata.sighting">
<field name="identifier" >20200102 B-S01</field>
<field name="description" >QWARTZ</field>
<field name="begin" >2020-01-02 17:50:00</field>
<field name="end" >2020-01-02 17:50:00</field>
<field name="location">94089 Neureichenau - Altreichenau</field>
<field name="case" ref="case_002"></field>
<field name="witnesses" eval="[(6, 0, [ref('witness_001'), ref('witness_002'), ref('witness_003')])]"></field>
</record>
<record id="sighting_003" model="ufodata.sighting">
<field name="identifier" >20190915 B-S01</field>
<field name="description" >QWURTZ</field>
<field name="begin" >2019-09-15 14:50:00</field>
<field name="end" >2019-09-15 14:50:00</field>
<field name="location">89584 Ehingen (Donau)</field>
<field name="case" ref="case_003"></field>
<field name="witnesses" eval="[(6, 0, [ref('witness_003')])]"></field>
</record>

<!-- -->
<!-- WITNESSES -->
<record id="witness_001" model="ufodata.witness">
<field name="sightings" eval="[(6, 0, [ref('sighting_001'), ref('sighting_002'), ref('sighting_003')])]"></field>
</record>

<record id="witness_002" model="ufodata.witness">
<field name="sightings" eval="[(6, 0, [ref('sighting_002')])]"></field>
</record>

<record id="witness_003" model="ufodata.witness">
<field name="sightings" eval="[(6, 0, [ref('sighting_003')])]"></field>
</record>

<record id="witness_004" model="ufodata.witness">
<field name="sightings" eval="[(6, 0, [ref('sighting_003')])]"></field>
</record>

<record id="witness_005" model="ufodata.witness">
<field name="sightings" eval="[(6, 0, [ref('sighting_003')])]"></field>
</record>

<!-- CASES -->
<record id="case_001" model="ufodata.case">
<field name="case_id" >20200102 A</field>
<field name="related_sightings" eval="[(6, 0, [ref('sighting_001')])]"/>
</record>
<record id="case_002" model="ufodata.case">
<field name="case_id" >20200102 B</field>
<field name="related_sightings" eval="[(6, 0, [ref('sighting_002')])]"/>
</record>
<record id="case_003" model="ufodata.case">
<field name="case_id" >20190915 B</field>
<field name="related_sightings" eval="[(6, 0, [ref('sighting_003')])]"/>
</record>
</odoo>

Avatar
Discard
Author Best Answer

Ok, found out myself:

First, I declare my "witnesses" as "persons":

<record id="witness_001" model="ufodata.person">
<!-- from ufodata.person -->
<field name="first_name" >Arthur</field>
<field name="middle_name" >C.</field>
<field name="surname" >Clarke</field>
<field name="age" >90</field>
<field name="birthday" >1917-12-16</field>
<field name="obit" >2008-03-19</field>
<field name="gender" >male</field>
<field name="addresses" eval="[(6, 0, [ref('address_004')])]" ></field>
</record>

Then I initialize my "adresses", who now find valid "persons" in the db.

Now, I *redeclare* my witnesses as "witness":

<record id="witness_001" model="ufodata.witness"/>

And that does the job. Strange. Seemingly, it's all about re-declaration.

Avatar
Discard