تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
5073 أدوات العرض

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
أكتوبر 23
22164
3
نوفمبر 21
7918
2
أكتوبر 21
8346
0
أغسطس 21
2
1
أكتوبر 20
17413