Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
5452 Prikazi

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
Opusti
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
Opusti
Avtor 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
Opusti
Related Posts Odgovori Prikazi Aktivnost
2
jan. 25
7227
1
apr. 24
3151
1
dec. 23
5709
2
nov. 22
4554
0
nov. 22
4246