Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
5086 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.
Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 1 25
6431
computed fields Đã xử lý
1
thg 4 24
2436
1
thg 12 23
4423
2
thg 11 22
3704
0
thg 11 22
3555