Search code examples
pythonpython-2.7odoo-8odooodoo-10

Odoo possibility to track changes on compute field


I have model A with compute field b (it depends on field c and field d values).

b = fields.Float(compute='_compute_field')

My task is every month compare past and current month field b values and get differences. For example I want to compare 2018-04-01 field b value with 2018-05-01 field b value. Firstly I was thinking to store compute value in database. But the problem is that I can't do that (store=True) because if I store field b value in database I always got 0 value on field b.

What can be other alternatives to track or store compute field values that I can compare the differences depend on time (date).


Solution

  • If you want to compare the values month per month I would run an automated (scheduled) task every month. Then, I would create a new record with the new value for the field b in the task method. So you would have a history of values in this way, one a month.

    Therefore, my recommendation is that you should create a normal field without the compute attribute:

    b = fields.Float()