This question has been flagged
3 Replies
11828 Views
I've got two models: Person, and Witness, which inherits from Person:

class Person(models.Model):
_name = 'ufodata.person'

first_name = fields.Char()
middle_name = fields.Char()
surname = fields.Char()
age = fields.Integer()
birthday = fields.Date()
obit = fields.Date()
gender = fields.Selection([
('male', 'Male'),
('female', 'Female'),
('other', 'Other')
], default="male", tracking=True)
addresses = fields.One2many('ufodata.address', 'resident', string='Addresses')

def name_get(self):
result = []
for record in self:
result.append((record.id, "%s %s %s" % (record.first_name, record.middle_name, record.surname)))
return result

class Witness(models.Model):
_name = 'ufodata.witness'
_inherit = {'ufodata.person'}
_rec_name = 'code_name'

code_name = fields.Char()
sightings = fields.Many2many('ufodata.sighting', 'sighting_witness_rel', string="Sightings")

I've got also two list views (I'll omit the form views, as inheriting them works fine):

<odoo>
<record id="view_tree_person" model="ir.ui.view">
<field name="name">Person List</field>
<field name="model">ufodata.person</field>
<field name="arch" type="xml">
<tree decoration-bf="first_name"
decoration-info="surname">
<field name="first_name" />
<field name="middle_name" />
<field name="surname" />
<field name="age" />
<field name="birthday" />
<field name="obit" />
<field name="gender" />
<field name="addresses" widget="many2many_tags" />
</tree>
</field>
</record>
</odoo>

<odoo>
<record id="view_tree_witness" model="ir.ui.view">
<field name="name">Witness List</field>
<field name="model">ufodata.witness</field>
<field name="inherit_id" ref="ufodata_app.view_tree_person" />
<field name="arch" type="xml">
<tree>
<field name="code_name" />
<field name="sightings" widget="many2many_tags" />
</tree>
</field>
</record>
</odoo>

Now inheriting the list view is NOT working.
(1) view_tree_witness will always show the "code_name" field in a column and nothing else.
(2) If I omit the "inherit_id" field entirely, inheritage will be assumed from the model and "code_name" is not found, producing an error
(3) The many2many field "sightings" is never shown
(4) If I add fields from the base view within the <tree> tag, they do not show up
<tree>
<field name="code_name" />
<field name="sightings" widget="many2many_tags" /> # not showing
<field name="first_name" /> # not showing
</tree>

To make it clear: none of these problems occur in form view, they are a tree view matter only. If I don't break the code entirely, I always
will have only one column in my view showing the code_name.

Avatar
Discard

Inheritance in models and views: https://goo.gl/4Zyc9d

Author

Thanks, but I'm already working with two of the three odoo books from packt, and if they tell what to do in my case, they hide it well.

Best Answer

Examples, first example add fields, next replace full tree:

<odoo>
<record id="view_tree_witness" model="ir.ui.view">
<field name="name">Witness List</field>
<field name="model">ufodata.witness</field>
<field name="inherit_id" ref="ufodata_app.view_tree_person" />
<field name="arch" type="xml">
<field name="addresses" position="after">
<field name="code_name" />
<field name="sightings" widget="many2many_tags" />
</field>
</field>
</record>
</odoo>


<odoo>
<record id="view_tree_witness" model="ir.ui.view">
<field name="name">Witness List</field>
<field name="model">ufodata.witness</field>
<field name="inherit_id" ref="ufodata_app.view_tree_person" />
<field name="arch" type="xml">
<tree position="replace">
<tree>
                <field name="code_name" />
<field name="sightings" widget="many2many_tags" />
<field name="first_name" />
                </tree>
           </tree>
</field>
</record>
</odoo>
PS. Probably you have problem with name field in sightings. How is defined ufodata.sighting?


Avatar
Discard
Author

Currently, I have a problem with updating my views ... as if the -u parameter of the odoo-bin cmd line would not work - have to deal with that problem first.

Author

I tried out both variants, but unfortunately neither makes a difference. The ONLY field that is shown in the tree view is "code_name", "sightings" is ignored, and also none of the base model/view fields shows up. Still have no idea what the problem could be.

Author

As for "sightings", model and view are defined as follows:

class Sighting(models.Model):

_name = 'ufodata.sighting'

_rec_name = 'identifier'

identifier = fields.Char()

description = fields.Text()

begin = fields.Datetime()

end = fields.Datetime()

location = fields.Char()

case = fields.Many2one('ufodata.case', string='Case')

investigator = fields.Many2one('ufodata.investigator', string='Investigator')

comments = fields.One2many('ufodata.sightingcomment', 'sighting', string='Comments')

witnesses = fields.Many2many('ufodata.witness', 'sighting_witness_rel', string="Witnesses")

<odoo>

<!-- FORM -->

<record id="view_form_sighting" model="ir.ui.view">

<field name="name">Sichtungen</field>

<field name="model">ufodata.sighting</field>

<field name="arch" type="xml">

<form string="Sightings">

<sheet>

<group>

<field name="identifier" />

<field name="description" />

<field name="begin" />

<field name="end" />

<field name="location" />

<field name="case" widget="many2one_tags" />

<field name="investigator" widget="many2one_tags" />

<field name="comments" widget="one2many_tags" />

<field name="witnesses" widget="many2many_tags" />

</group>

</sheet>

</form>

</field>

</record>

<!-- LIST -->

<record id="view_tree_sighting" model="ir.ui.view">

<field name="name">Sightings List</field>

<field name="model">ufodata.sighting</field>

<field name="arch" type="xml">

<tree decoration-bf="identifier">

<field name="identifier" />

<field name="description" />

<field name="begin" />

<field name="end" />

<field name="location" />

<field name="case" widget="many2one_tags" />

<field name="investigator" widget="many2one_tags" />

<field name="comments" widget="one2many_tags" />

<field name="witnesses" widget="many2many_tags" />

</tree>

</field>

</record>

<!-- KANBAN -->

<record id="view_kanban_sighting" model="ir.ui.view">

<field name="model">ufodata.sighting</field>

<field name="arch" type="xml">

<kanban>

<field name="case" />

<field name="identifier" />

<field name="description" />

<field name="begin" />

<field name="end" />

<field name="location" />

<templates>

<t t-name="kanban-box">

<div class="sighting_kanban_card">

<a type="open">

<field name="case" />

</a>

</div>

</t>

</templates>

</kanban>

</field>

</record>

</odoo>

Review all views assigned to this model. You can delete them all and re-update the whole system with "-u all" parameters

Author Best Answer
(Sorry, still confusing comments and answers)


Avatar
Discard
Best Answer

Can anyone tell me

where is existing tree view id is located. i want to use to inherit new form which will locate in tree view.

Avatar
Discard

Go to Tree view you want to inherit -> Click Debug button -> Edit View : List -> External ID