Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

Help wanted with contributing first (very stupid) module

by
Coop IT Easy SC agréée, Carmen Bianca Bakker
- 12/10/2022 16:47:53
Hi all,

Feeling motivated by the OCA Days, I'm thinking of contributing a
(rather incredibly stupid, but moderately handy) module to the OCA.
I've been contributing through PRs and reviews, but I've not yet pushed
any of my own modules.

The module in question is ``company_today``[1], and its description is
as follows:

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.

---

It's a rather silly module, but I've found it useful and charming.

1. How would I find a good repository to contribute this module to?
There are _heaps_.

2. Because I'm testing the waters; is this sort of module the sort of
module that has a right to live within the OCA?

Gratefully, and with collaborative regards,
Carmen


[1]: https://github.com/coopiteasy/addons/tree/12.0/company_today

Follow-Ups