EMS

Students coming of age

models/contacts/coming_of_age.py (ResPartnerComingOfAge, issue #690). One daily check finds the students who just turned 18 and calls a hook on them, so every feature that has to do something that day plugs into the same place instead of growing its own cron.

Live checks vs. actions on the day

Most of EMS needs nothing from this: it reads is_adult (res.partner, computed from birth_date against the company’s today, never stored) at the moment it runs, so it follows the birthday on its own:

Reads is_adult when it runs Where
Who gets attendance, coexistence and notice emails (the family while a minor or with auth_share) attendance_session.py, strike.py, notice.py, portal.py (_ems_notification_recipients)
Who acts for the student on the portal, who files requests portal.py (_ems_portal_can_act_for and neighbours)
Contact data request: what is required, who receives it contact_data_request.py
Convalidation resolution and authorization recipients convalidation.py, authorization_send_wizard.py

What the hook is for is state kept somewhere else, or a one-off action that has to happen that day: the Google account’s OU (already wired), and later things such as telling the student and the family what changes, or asking the student for the authorization to share with the family.

Flow

flowchart LR
    C[ir_cron_students_coming_of_age<br/>daily] --> W["window (lastcall, today]"]
    W --> S[_ems_students_coming_of_age:<br/>active students whose 18th birthday is in the window]
    S --> H[_ems_on_coming_of_age]
    H --> G[Google Workspace: _gw_enqueue_relocate<br/>adults OU, queued]
    H -.-> F[future extensions]

Adding an action

Extend the hook on res.partner and call super():

def _ems_on_coming_of_age(self):
    super()._ems_on_coming_of_age()
    self.filtered(...)._my_feature_action()  # filter out whoever it does not apply to

Tests

tests/test_coming_of_age.py (TestComingOfAge): today’s birthdays (minors, archived students and non-students left out), the catch-up after missed runs and the no-repeat window. They patch the hook, so no feature’s action runs on the development data the test shards clone. Each extension tests its own part: test_coming_of_age_relocates_the_account in tests/test_student_google_workspace.py.