Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
5549 Widoki

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

Awatar
Odrzuć
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!

Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
gru 22
15273
1
lis 21
5366
0
sty 21
2621
8
maj 20
8254
0
gru 23
3191