Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
5085 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
2
Jan 25
6431
computed fields Diselesaikan
1
Apr 24
2436
1
Des 23
4423
2
Nov 22
3704
0
Nov 22
3554