Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] company_today: Document raison d'être in description #264

Open
wants to merge 1 commit into
base: 12.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion company_today/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
Store today's date on the company module. A cronjob makes sure this field stays
Store today's date on the company model. A cronjob makes sure this field stays
up-to-date.

The use-case for this module is as follows. Imagine you have two regular fields
and a computed field::

amount = fields.Monetary()
payment_date = fields.Date()
cost_per_day = fields.Monetary(compute="_compute_cost_per_day")

@api.depends("amount", "payment_date")
def _compute_cost_per_day(self):
today = fields.Date.today()
for record in self:
delta = today - record.payment_date
record.cost_per_day = record.amount / delta.days

When the next day arrives, ``cost_per_day`` should be re-computed, but it won't
be, because none of the dependencies have changed.

With this module, you can add a dependency on "company_id.today" (assuming that
your model has a res.company field, which is trivial to add). This way, you get
all the benefits of having a compute cache, and your field will be recomputed
when the date changes.