Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
1368 Vizualizări

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.

Imagine profil
Abandonează
Cel mai bun răspuns

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



Imagine profil
Abandonează
Autor Cel mai bun răspuns

perfect, thanks for your help. :)

Imagine profil
Abandonează
Cel mai bun răspuns

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 :)

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
oct. 23
4008
0
iun. 22
23
4
iun. 25
3608
0
dec. 23
1309
0
nov. 23
1279