Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
5095 มุมมอง

Hi,


I want to add a field with Odoo Studio that shows one specific field of one specific line?


Example:

  • I have a sale order with 5 order lines

  • One of those order lines has the product type 'BIG'

  • How can I create a field on the sale order showing the (first) product where product type = 'BIG'?

Odoo version 12.0

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi Bas,

While there's a few ways to do this, I find the most readable to be a computed field with something like this:

for rec in self:
  line = rec.order_line.filtered(lambda l: l.product_id.product_type == 'big')
  if line:
    rec['x_studio_first_big_product'] = line[0].product_id
  else:
    rec['x_studio_first_big_product'] = False
This filters the lines down to only those that are of product type big, and if any exist, uses the first ones product. You would need to add a dependency for order_line.product_id.product_type.
อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Thanks for your quick respons!

I'm trying but I'm new to this so probably doing something wrong, what I have:

Fields

  • x_studio_verkooporderregel_vlookup = new studio field where I'm trying to get the first line

  • x_studio_type_product = product type, atrribute of the (sale) order line

  • When x_studio_type_product = 'Zonnepanelen' , it needs to show first record


Dependency: 

order.line.product_id.x_studio_type_product

Code:

for rec in self:

  line = rec.sale.order.line.filtered(lambda l: l.product_id.x_studio_type_product == 'Zonnepanelen')

  if line:

    rec['x_studio_verkooporderregel_vlookup'] = line[0].product_id

  else:

    rec['x_studio_verkooporderregel_vlookup'] = False

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ม.ค. 25
6448
computed fields แก้ไขแล้ว
1
เม.ย. 24
2445
1
ธ.ค. 23
4439
Menu item for users and group only แก้ไขแล้ว
2
พ.ย. 22
3721
0
พ.ย. 22
3568