diff --git a/website_event_attendee_signup/data/mail_template_data.xml b/website_event_attendee_signup/data/mail_template_data.xml index 585fc71..5f46611 100644 --- a/website_event_attendee_signup/data/mail_template_data.xml +++ b/website_event_attendee_signup/data/mail_template_data.xml @@ -2,34 +2,42 @@ Event: Signup - + {{ (object.event_id.organizer_id.email_formatted or object.event_id.user_id.email_formatted or '') }} Welcome to our Portal! - ${object.attendee_partner_id.id} + {{object.attendee_partner_id.email or object.partner_id.email}} - ${object.attendee_partner_id.lang} {{object.attendee_partner_id.lang or object.event_id.lang or object.partner_id.lang}} +

- Hello ${object.attendee_partner_id.name},
+ Hello ,
- You was registered as attendee of ${object.event_id.name}. + You was registered as attendee of . - % if object.attendee_partner_id.signup_token: + Use the link below to sing-up on portal to access your event dashboard: -

+ - % endif +

Best regards,

- ]]> + diff --git a/website_event_attendee_signup/models/event_registration.py b/website_event_attendee_signup/models/event_registration.py index 8a47950..318cabf 100644 --- a/website_event_attendee_signup/models/event_registration.py +++ b/website_event_attendee_signup/models/event_registration.py @@ -1,24 +1,41 @@ -from odoo import api, models +from odoo import models class EventRegistration(models.Model): _inherit = "event.registration" - @api.model - def create(self, vals): - res = super().create(vals) - - if res.event_id.attendee_signup and res.attendee_partner_id: - login = res.attendee_partner_id.email - user = self.env["res.users"].search([("login", "=ilike", login)]) - if not user: - user = ( - self.env["res.users"] - .sudo() - ._signup_create_user( - {"login": login, "partner_id": res.attendee_partner_id.id} - ) - ) - user.partner_id.signup_prepare() - - return res + def _update_attendee_partner_id(self, vals): + vals = super()._update_attendee_partner_id(vals) + if not vals.get("attendee_partner_id"): + return vals + + if not vals.get("event_id"): + return vals + + Partner = self.env["res.partner"].sudo() + Users = self.env["res.users"].sudo() + Events = self.env["event.event"].sudo() + + event = Events.browse(vals["event_id"]) + if not event.attendee_signup: + return vals + + attendee_partner = Partner.browse(vals["attendee_partner_id"]) + if attendee_partner.user_ids: + # already has user + return vals + + login = attendee_partner.email + if not login: + return vals + + user = Users.search([("login", "=ilike", login)]) + if user: + # already has user with given address + return vals + + user = Users._signup_create_user( + {"login": login, "partner_id": attendee_partner.id} + ) + user.partner_id.signup_prepare() + return vals