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

Hi, 

I'm trying to create a new field for a list view that simply multiplies the "shipping_weight" field by 0.4536


Reason is that I have 2 businesses on the database, no.1 primarily uses pounds as the weight and no.2 uses Kg. 
Unfortunately Odoo doesn't allow each company to use a different primary UoM.
When arranging freight for company no.2 its in Kg with the haulier so I just want to multiply the "shipping_weight" * 0.4536 to roughly convert Lb to Kg.


I have created a floating field in studio called "x_studio_weight_kg_1" and thought it would be something simple in the compute field like;
result = shipping_weight * 0.45359 
or
for record in self: 

                        record[x_studio_weight_kg_1] = shipping_weight * 0.45359

but evidently its something else, any help would be appreciated.

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

you are missing the "record." when getting the  shipping_weight 


try this:

for rec in self:

    rec['x_studio_new_shiping_weight'] = rec.shipping_weight * 0.45359



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

perfect, thanks for your help. :)

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

Hello Raphael,

In the computed field formula, enter the following code:

for record in self:
    record['x_studio_weight_kg_1'] = record['shipping_weight'] * 0.4536

Make sure to add the x_studio_weight_kg_1 field to the list/form view to ensure the conversion is reflected correctly. Also, don't forget to set shipping_weight as a dependency for the x_studio_weight_kg_1 field, so it updates automatically when the shipping weight changes.

This will correctly compute the weight in kilograms by multiplying the shipping_weight by 0.4536.

I have attached a screenshot for your reference to help clarify the setup.



Let me know, if it helps :)

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 10 23
4062
0
thg 6 22
23
4
thg 6 25
3683
0
thg 12 23
1361
0
thg 11 23
1354