Karl Hunt Karl Hunt - 2 months ago 27
Python Question

Odoo 9 Empty Tree View

I have created a new model and added a tree view to edit/view it on the res.partner view.

I can create entries no problem and they appear in the database. I cannot however get the tree view to display any data at all. Even with the filters removed.

Here is the view xml

<page string="Projects/Training">
<field name="training_logs" context="{'default_tl_partner_id': active_id}" domain="[('tl_partner_id','=',active_id)]">
<tree string="Training Logs" editable="top">
<field name="tl_partner_id" invisible="1"/>
<field name="tl_date"/>
<field name="tl_trainer"/>
<field name="tl_present"/>
<field name="tl_summary"/>
</tree>
</field>
</page>


Model Structure as requested

class training_log(osv.Model):
_name='training.log'
_description='Log of past training events'
_order='tl_date'
_columns = {
'tl_partner_id': fields.many2one('res.partner', 'Customer'),
'tl_date': fields.date("Training Date"),
'tl_trainer': fields.many2one('res.users', 'Trainer'),
'tl_present': fields.char('People Present'),
'tl_summary': fields.text('Training Summary')
}


res.partner - I have left out all my non related fields.

class res_partner(osv.osv):
_inherit = "res.partner"
_columns = {

'training_logs': fields.one2many('training.log','id','Training Logs'),



}

Answer

When we define one2many field, we need to give proper many2one field name.

In your case, you have given id which means it will take currently record not for as you have created new object training.log

Try with following code:

Replace

'training_logs': fields.one2many('training.log','id','Training Logs'),

with

'training_logs': fields.one2many('training.log','tl_partner_id','Training Logs'),

Afterwards, restart Odoo server and upgrade module.