Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2554 Visualizações

I've created 2 new margin custom fields:

x_studio_total_margen_2 in sale.order.line that calculates a new margin from other costs.

x_studio_margen_2 in sale.order that is supposed to be the sum of every x_studio_total_margen_2 line added by the new formula:

for record in self:
    total = 0
    for line in record.order_line:
        total += line.x_studio_total_margen_2
    record['x_studio_margen_2'] += total

And it does the sum but it's not working well because it only makes a sum when I would like to have a correction update. For example:

If I have a product that costs 2€ and the sell price_unit is 6€ I will have a x_studio_margen_2 = 4€ but if I decide to change the price_unit to 5€due to whatever, x_studio_margen_2 is not going to be 3€ but the sum of the last x_studio_margen_2 = 4 + the new margin = 3, so the updated margin will be 7€ while it's supposed to be 3€.

Same happens when if I delete a product, x_studio_margen_2 doesn't changes, it's going to be the last number.

How can I fix it??

I know where the problem is but I don't get a solution.

Thank you!


Avatar
Cancelar

First avoid study

Autor

I don't get if you mean that I'm not working on solving this by myself or if you mean to avoid Studio app from Odoo.

Publicações relacionadas Respostas Visualizações Atividade
2
jan. 24
5430
0
jun. 23
2028
1
dez. 22
3339
1
abr. 19
6204
2
jul. 25
3820