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

I'm using Odoo 18.3 online.

I want to create a calculated field on the product page with Studio. This should use the listprice (list_price) but also the value of one of the attributes the product has.

I guess I have to somehow use attribute_line_ids, but I’m not sure how I can find the value of one specific attribute to use in the calculation.

Any pointers?

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

I get the following error when trying this:

ValueError: NameError("name 'attribute_value_ids' is not defined") while evaluating
'for record in self:\n    record["x_studio_fles_inhoud"] = float(attribute_value_ids[0].name)'

I also tried:  product_template_variant_value_ids

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

Hi,

Go to Products → Variants

Odoo stores attribute values per variant , not in the product template.

Open Odoo Studio

Click the Studio (wrench) icon while on a product variant form.

Click Add Field

  • Choose field type: Monetary or Float
  • Name it something like Calculated Price
  • Enable "Computed Field"

In the Compute field editor , use this expression:

If you're using an attribute like "Weight" with values like 10, 20, etc.:

list_price + float(attribute_value_ids[0].name)


This assumes:

  • Only 1 attribute is used
  • The value is numeric (like 10, 20…)


If You Have Text Attribute (eg Light, Medium, Heavy):

Use this instead:

list_price + (

  1 if attribute_value_ids[0].name == 'Light' else

  5 if attribute_value_ids[0].name == 'Medium' else

  10 if attribute_value_ids[0].name == 'Heavy' else 0

)


i hope it is usefull

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 25
239
1
thg 7 25
1142
2
thg 3 25
1409
0
thg 2 25
1079
0
thg 2 25
1219