Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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,
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:
B_id = fields.One2many(comodel_name='B', inverse_name='A_id')
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.
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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 9/24/15, 6:42 AM|
|Seen: 489 times|
|Last updated: 9/25/15, 3:48 AM|