Skip to Content
Menu
This question has been flagged
2 Replies
4451 Views

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

Avatar
Discard
Best Answer

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.
Avatar
Discard
Author Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
1
Apr 24
1466
1
Dec 23
2726
2
Nov 22
2416
0
Nov 22
2736
0
Oct 22
1065