Odoo Help


Display recordset into record

on 9/24/15, 6:42 AM 628 views


I have 2 models A and B.
A is related to B like 

class B(models.Model):
A_id = fields.Many2one(comodel_name='A', inverse_name=id)

So A have many B.
On the each A arch views i want to display all B records (same order and order_lines)

How to do this in the PY and in the XML.
All example if found are very difficult to reproduce.

For now i put this in the PY

all_my_B_records = self.env['B'].search([('B_id', '=', id)])

I don't know at all if it is a good start :)

Thanks for your help,




| 6 5 7
Tbilisi, Georgia
On 9/24/15, 7:00 AM

for the beginning, create an oposite inversed relation field (in your case, for Many2one field it'll be field of type One2many), and use that field in inverse_name argument instead of id, so your code will become as follows: 

class A(models.Model):
B_id = fields.One2many(comodel_name='B', inverse_name='A_id')

class B(models.Model):
A_id = fields.Many2one(comodel_name='A', inverse_name='B_id')

now, as both models are connected with inversed relations, you can simply add the related field to the view for class A in XML.

<field name="B_id" />

it'll display corresponding list using one2many widget.

Thank you!!!!!

on 9/25/15, 3:48 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: 9/24/15, 6:42 AM
Seen: 628 times
Last updated: 9/25/15, 3:48 AM