Odoo Help


This community 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.


Calculated field depends on current date

on 6/7/15, 9:26 AM 459 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"

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


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