Help

0

How to declare test data for derived classed?

Avatar
Ingbert Jüdt
I've got three models: a base model "Person", and derived models "Witness" and "Investigator", which by inheritage are also of type "Person".

Now I'm declaring data for witness nr. 1:

<!-- INIT BASE CLASS (PERSON) -->
<record id="witness_001" model="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')])]" />
</record>
<!-- UPDATE CLASS (WITNESS) -->
<record id="witness_001" model="ufodata.witness">
<field name="code_name" >Schätzelchen</field>
</record>
<record id="address_004" model="ufodata.address">
<field name="resident" ref="witness_001" />
</record>
<record id="witness_001" model="ufodata.person">
<field name="addresses" eval="[(6, 0, [ref('address_004')])]" />
</record>

This code works.

Now I'm doing the same for Investigator Nr. 1:

<!-- INIT BASE CLASS (PERSON) -->
<record id="investigator_001" model="ufodata.person">
<field name="first_name" >Walburga</field>
<field name="middle_name" />
<field name="surname" >Weißnix</field>
<field name="age" >24</field>
<field name="birthday" >1995-03-01</field>
<field name="gender" >female</field>
<field name="addresses" eval="[(6, 0, [ref('address_009')])]" />
</record>
<!-- UPDATECLASS (INVESTIGATOR) -->
<record id="investigator_001" model="ufodata.investigator">
<field name="user_name" >wweissnix</field>
<field name="assigned_cases" eval="[(6, 0, [ref('case_001')])]" />
<field name="researched_sightings" eval="[(6, 0, [ref('sighting_001')])]" />
<field name="organizations" eval="[(6, 0, [ref('ufoorg_gep'),ref('ufoorg_degufo'),ref('ufoorg_mufon')])]" />
<field name="first_name" >Walburga</field>
<field name="middle_name" />
<field name="surname" >Weißnix</field>
<field name="age" >24</field>
<field name="birthday" >1995-03-01</field>
<field name="gender" >female</field>
</record>

This code does NOT work. Error message:
odoo.tools.convert.ParseError: "Wrong value for ufodata.address.resident: ufodata.investigator(1,)"

Of course, "Address" holds a relation to a Person, which is a resident at the given address. These addresses are initialized beforehand. Now syntactically, initializing Witness is exactly the same as initializing Investigator. But the second case results in a fail.

I CAN produce a version that initializes error-free, but then the witnesses will point to the correct residents (via "address"), and the investigators will point to the wrong ones (also via "address").

What makes Odoo a pain in the ass in this case is that I perfectly know THAT the data declarations will result in a sequence of SQL queries, but not HOW. I'ts all guesswork and trial-and-error, and neither the online documentation nor the books are tackling the level-of-detail that would provide me with an answer.
Avatar
Discard