Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
3 Respostas
1224 Visualizações

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.

Avatar
Cancelar
Melhor resposta

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



Avatar
Cancelar
Autor Melhor resposta

perfect, thanks for your help. :)

Avatar
Cancelar
Melhor resposta

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

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
2
out. 23
3846
0
jun. 22
23
4
jun. 25
3409
0
dez. 23
1218
0
nov. 23
1141