Odoo Help


Calculated field depends on current date

on 6/7/15, 9:26 AM 1,099 views

I want to sort my lists by a computed field "due_days" (number of days - computed from "due_date").

I could do this by setting "store=True" on due_days, but then the compute method depends on the current date. How can I then be sure, that the value is re-computed when the current date changes?

It would also be easy to implement a new search method. Searching on due_days is the same as searching on due_date with ASC/DESC order reversed. But how can I tell Odoo to sort by this order?

On 7/13/15, 2:51 PM

I'm aware of the @api.depends decorator, but as far as I can see, it can only be triggered by other fields. As the "due_days" field depends on both "due_date" and the current date, we also need to re-calculate due_days when the current date changes.

Maybe I wasn't clear on the sorting, but I want the user to be able to choose the sorting when they see a list.

On 7/13/15, 9:55 AM

Assuming you are using odoo8, you can decorate you method for your computed field with @api.depends("field.name.here")

And to sort search results for a model, in that model's class (python) you can add _order = "fieldname ASC, otherfieldname DESC"

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/7/15, 9:26 AM
Seen: 1099 times
Last updated: 7/13/15, 2:51 PM