Skip to Content
Menu
This question has been flagged
1 Reply
4942 Views

I am trying to get all Purchase Order Lines on product form view in a one2many relational field.


If I add bellow relation[bold] on product.template, it won't work because purchase order line has no inverse relation with product.template, rather it has relation with product.product


Similarly if I add it on product.product, pythonically it will work, but I wont be able to get on product form view as the view is defined for product.template.

pol_ids = fields.One2many('purchase.order.line', 'product_id', string='Purchases')

 

To make it simple: How can we get all purchase order lines( in one2many) on product form view? 

Avatar
Discard
Best Answer

Hello Fazal Haleem

As we know product_template have no relation with purchase_order_line directly you could below code and it will show you related purchase order line in product_template view.

class purchase_order_line(models.Model):
_inherit = "purchase.order.line"
product_template_id=fields.Many2one("product.template",related="product_id.product_tmpl_id")

class product_template(models.Model):
_inherit = "product.template"
purchase_line_ids = fields.One2many("purchase.order.line","product_template_id")

Now you can put purchase_line_ids fields in product template view.

Hope this will Help you.

Thanks,

Husain

Avatar
Discard
Related Posts Replies Views Activity
3
Oct 23
21859
3
Nov 21
7787
2
Oct 21
8208
0
Aug 21
2
1
Oct 20
17126