Skip to content

Commit 9006bdd

Browse files
committed
[IMP] company_today: Document raison d'être in description
I'm drafting an e-mail to the OCA contributors list with a description of this module, and I thought I'd backport it to the repository. Signed-off-by: Carmen Bianca Bakker <[email protected]>
1 parent 0f05213 commit 9006bdd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

company_today/readme/DESCRIPTION.rst

+22
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
11
Store today's date on the company module. A cronjob makes sure this field stays
22
up-to-date.
3+
4+
The use-case for this module is as follows. Imagine you have two regular fields
5+
and a computed field::
6+
7+
amount = fields.Monetary()
8+
payment_date = fields.Date()
9+
cost_per_day = fields.Monetary(compute="_compute_cost_per_day")
10+
11+
@api.depends("amount", "payment_date")
12+
def _compute_cost_per_day(self):
13+
today = fields.Date.today()
14+
for record in self:
15+
delta = today - record.payment_date
16+
record.cost_per_day = record.amount / delta.days
17+
18+
When the next day arrives, ``cost_per_day`` should be re-computed, but it won't
19+
be, because none of the dependencies have changed.
20+
21+
With this module, you can add a dependency on "company_id.today" (assuming that
22+
your model has a res.company field, which is trivial to add). This way, you get
23+
all the benefits of having a compute cache, and your field will be recomputed
24+
when the date changes.

0 commit comments

Comments
 (0)