-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.py
20 lines (18 loc) · 868 Bytes
/
hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Copyright 2019 David Vidal
# License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html
from odoo import SUPERUSER_ID, api
def post_init_hook(cr, registry):
"""Preload proper attendee partner for existing registrations using
the same rules the module does"""
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
attendees_emails = env["event.registration"].read_group(
[("email", "!=", False)], ["email"], groupby="email"
)
for email in attendees_emails:
attendee_partner = env["res.partner"].search(
[("email", "=ilike", email["email"])], limit=1
)
if attendee_partner:
attendees = env["event.registration"].search(email["__domain"])
attendees.write({"attendee_partner_id": attendee_partner.id})