Skip to Content
Menú
This question has been flagged
2 Respostes
5543 Vistes

Hello, I have Odoo8.

In a model A I have a One2many field and a Many2many field. The related models has fields which are float values. I want to add a computed field in the model A that sums all the float values of the other two models related. How can I do?

I do this but not works (in cases return value 0 and in cases only one value, not the sum)

    @api.one
    @api.depends('pays')
    def _actualiza_monto(self):
        total_comprado = 0
        for compra in self.pays
            total_comprado = total_comprado + compra.amount_total

    self.computed_field = total_comprado

Avatar
Descartar
Autor

@vasanth, If I use @api.one means that I use one self record, isn't it? I want to use one record of self (sale.order) which has a collection of pays.

Autor

@zbik, I have the tab formatting correctly, when I do copy paste to the forum I do the mistake... in my .py file I have it correctly. Sorry!

Best Answer

Hi Jose ,

If you are using for loop means you should use @api.multi..If you use @api.one means it returns only one value

So the cosde should be:

    @api.multi
    @api.depends('pays')
    def _actualiza_monto(self):
        total_comprado = 0
        for compra in self.pays
            total_comprado = total_comprado + compra.amount_total

     self.computed_field = total_comprado

Avatar
Descartar
Best Answer

Hi Jose, probably your problem is related to the tab formatting, last line is without tab and is outside of method?

@api.one
@api.depends('pays')
def _actualiza_monto(self):
    total_comprado = 0
    for compra in self.pays
        total_comprado = total_comprado + compra.amount_total
    self.computed_field = total_comprado

Avatar
Descartar
Related Posts Respostes Vistes Activitat
2
de des. 22
15254
1
de nov. 21
5339
0
de gen. 21
2613
8
de maig 20
8222
0
de des. 23
3160