- company_id = fields.Many2one('res.company', string='Company', change_default=True,
- default=lambda self: self.env['res.company']._company_default_get('event.event'),
- required=False, readonly=False, states={'done': [('readonly', True)]})
- organizer_id = fields.Many2one('res.partner', string='Organizer',
- default=lambda self: self.env.user.company_id.partner_id)
-
- is_subscribed = fields.Boolean(string='Subscribed',
- compute='_compute_subscribe')
-
- @api.one
- def _compute_auto_confirm(self):
- self.auto_confirm = self.env['ir.values'].get_default('marketing.config.settings', 'auto_confirmation')
-
- @api.one
- @api.depends('registration_ids')
- def _count_registrations(self):
- self.count_registrations = len(self.registration_ids)
-
- @api.one
- @api.depends('registration_ids.user_id', 'registration_ids.state')
- def _compute_subscribe(self):
- """ Determine whether the current user is already subscribed to any event in `self` """
- user = self.env.user
- self.is_subscribed = any(
- reg.user_id == user and reg.state in ('open', 'done')
- for reg in self.registration_ids
- )