Odoo Help


Releated field not working

on 4/7/16, 5:51 AM 796 views

I'm trying to follow this video tutorial: http://www.odooclass.com/shop/product/mastering-odoo-9-development-6-intermediate-odoo-development-109

In my case I can't get the realeated field to work. In my case it always shows 0, no matter what I set in Products.

Here are my models:

class Dietfacts_product_template(models.Model):

_name = 'product.template'

_inherit = 'product.template'

calories = fields.Integer('Calories')

servingsize = fields.Float('Serving size')

lastupdated = fields.Date('Last Updated')

#dietitem = fields.Boolean('Diet item')

class Dietfacts_res_users_meal(models.Model):

_name = 'res.users.meal'

name = fields.Char('Meal name')

meal_date = fields.Datetime('Meal Date')

item_ids = fields.One2many('res.users.mealitem', 'meal_id')

user_id = fields.Many2one('res.users','Meal User')

notes = fields.Text('Meal notes')

class Dietfacts_res_users_mealitem(models.Model):

_name = 'res.users.mealitem'

meal_id = fields.Many2one('res.users.meal', 'Meal')

item_id = fields.Many2one('product.template', 'Item')

servings = fields.Float('Servings')

calories = fields.Integer(releated='item_id.calories', string='Calories per serving', store=True, readonly=True)

notes = fields.Text('Meal item notes')

And my xml view:

<menuitem action="meal_action_dietfacts" id="menu_meal_action_dietfacts" parent="base.menu_sales" sequence="15" />

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

<field name="model">res.users.meal</field>

<field name="view_type">form</field>

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



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

<field name="meal_date"></field>

<field name="user_id"></field>

<field name="notes"></field>



<page name="mealitems" string="Meal Items">

<field name="item_ids" widget="one2many_list">

<tree string="Meal Items" editable="bottom">

<field name="item_id" />

<field name="calories" />

<field name="servings" />

<field name="notes" />








Btw, this forum is terrible for pasting code.

Please add in the errorstack, this always gives great hints! Also, yes this forum is terrible for pasting code.

on 4/7/16, 6:02 AM

There's no stacktrace and no error. The terminal output looks fine. Everything works as it should except the mealitems values are zero.

on 4/7/16, 6:32 AM

Also this forum doesn't have a feature to edit my comment. I have to correct myself... calories values are zero, not mealitems.. :(

on 4/7/16, 6:34 AM
Diego Vázquez
On 4/7/16, 8:35 AM

i don't know if your copy-paste is literal of your code, but you have an error. Put related instead of releated

Unbelievable.. for the moment I thought this was it, but after I corrected my typo I still see the calories values as '0'... Nooooo :(

on 4/7/16, 9:30 AM

mmm, i don't see another error. Have you saved + restarted server + update module?

Diego Vázquez
on 4/7/16, 10:20 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 4/7/16, 5:51 AM
Seen: 796 times
Last updated: 4/11/16, 9:21 AM