[Django]-Field back to zero after save

2👍

It should be enough to use b_id on your compute method, because it’s related:

@api.multi
@api.depends('b_id')
def compute_all(self):
    for record in self:
        record.all_taxes = record.b_id.tax_value + record.tax_old

The compute method can be called with a multi record recordset. So use a for loop inside it. And you don’t have to do an update() at the end.

1👍

You can try it

    @api.one
    @api.depends('b_id', 'b_id.tax_value')
    def compute_all(self):
        self.all_taxes = self.tax_value + self.tax_old

Two things:

It ist compute not _compute and you don’t need to use self.update().

👤qvpham

0👍

Try this instead:

# You'll need this
from django.db.models import F

@api.depends('tax_value')
def compute_all(self):
    self.update(all_taxes=F('tax_value') + F('tax_old'))

You’re missing the self. What you’ve done is defined a local variable called all_taxes, not the instance variable.. which is what you’re after

Leave a comment