コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
5070 ビュー

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? 

アバター
破棄
最善の回答

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

アバター
破棄
関連投稿 返信 ビュー 活動
3
10月 23
22164
3
11月 21
7916
2
10月 21
8343
0
8月 21
2
1
10月 20
17412