From 003fc6c3f9bfb88c2101b9fa723bce40d1061791 Mon Sep 17 00:00:00 2001 From: Carmen Bianca Bakker Date: Wed, 12 Oct 2022 16:30:43 +0200 Subject: [PATCH] =?UTF-8?q?[IMP]=20company=5Ftoday:=20Document=20raison=20?= =?UTF-8?q?d'=C3=AAtre=20in=20description?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- company_today/readme/DESCRIPTION.rst | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/company_today/readme/DESCRIPTION.rst b/company_today/readme/DESCRIPTION.rst index 5f5a456af..3bc1cf6f0 100644 --- a/company_today/readme/DESCRIPTION.rst +++ b/company_today/readme/DESCRIPTION.rst @@ -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.