How to calc and update a field before save?

Just make calc_estoque a class method. Take it out of hooks.

def validade(self):
   self.calc_estoque()

Alternatively you could call it on before_insert but validate is better since you have some not-less-than-zero logic in there.

2 Likes