I added two float fields (previous_count and current_count) to account.move.line. What I want to achieve is to set the value of quantity to current_count - previous_count. This works the way I want it to, however, when I save the invoice, the value of current_count and previous_count is reset to zero, instead of maintaining the value I entered. But the value of quantity is saved
This is my code
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
previous_count = fields.Float(string='Previous Reading')
current_count = fields.Float(string='Current Reading')
@api.onchange('current_count')
def _onchange_current_count(self):
for line in self:
line.quantity = line.current_count - line.previous_count
I have read several articles about overriding the create/write methods. I tried to do that, but it still wasn't working. How can I get the value of current_value and previous_value to be saved?
Thanks for any help given...