Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5339 Lượt xem

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? 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 10 23
22610
3
thg 11 21
8142
2
thg 10 21
8534
0
thg 8 21
2
1
thg 10 20
17812