crm_lead.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import fields, models, api
  4. class Lead(models.Model):
  5. _inherit = 'crm.lead'
  6. event_lead_rule_id = fields.Many2one('event.lead.rule', string="Registration Rule", help="Rule that created this lead")
  7. event_id = fields.Many2one('event.event', string="Source Event", help="Event triggering the rule that created this lead")
  8. registration_ids = fields.Many2many(
  9. 'event.registration', string="Source Registrations",
  10. groups='event.group_event_registration_desk',
  11. help="Registrations triggering the rule that created this lead")
  12. registration_count = fields.Integer(
  13. string="# Registrations", compute='_compute_registration_count',
  14. groups='event.group_event_registration_desk',
  15. help="Counter for the registrations linked to this lead")
  16. @api.depends('registration_ids')
  17. def _compute_registration_count(self):
  18. for record in self:
  19. record.registration_count = len(record.registration_ids)
  20. def _merge_dependences(self, opportunities):
  21. super(Lead, self)._merge_dependences(opportunities)
  22. # merge registrations as sudo, as crm people may not have access to event rights
  23. self.sudo().write({
  24. 'registration_ids': [(4, registration.id) for registration in opportunities.sudo().registration_ids]
  25. })
  26. def _merge_get_fields(self):
  27. return super(Lead, self)._merge_get_fields() + ['event_lead_rule_id', 'event_id']