Odoo Help

Welcome!

This community 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.

0

Display recordset into record

By
Sebastian782
on 9/24/15, 6:42 AM 321 views

Hi,

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,
Sebastian

0

Temur

--Temur--
2896
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
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!!!!!

Sebastian782
on 9/25/15, 3:48 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/24/15, 6:42 AM
Seen: 321 times
Last updated: 9/25/15, 3:48 AM