Files
odoo_source/addons/event_crm/models/crm_lead.py
T
std-odoo be996fdc00 [IMP] crm_*: add more fields when we merge multiple leads
Purpose
=======
Add more fields when we merge multiple leads to be sure not lose
valuable information.

Specifications
==============
Those fields are propagated to the destination if the value on the
destination is Falsy
- referred
- color
- recurring_revenue
- recurring_plan
- function
- lang_id
- date_deadline
- reveal_id
- lead_mining_request_id
- reveal_ip
- reveal_iap_credits
- reveal_rule_id
- event_lead_rule_id
- event_id

The "lost_reason" field is propagated to the destination only if it's
lost (otherwise, it makes no sense to have a lost reason on a non-lost
lead).

The field "iap_enrich_done" is set to True if at least one lead has been
enriched.

We also keep the sum of all the lead tags (and remove any potential
duplicates).

The address is taken from the lead with the most non-empty address
fields (sorted by highest rank if multiple lead have the same amount
of non-empty fields).

Task-2447721
PR odoo/odoo#75742
2021-10-19 15:58:58 +00:00

36 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, api
class Lead(models.Model):
_inherit = 'crm.lead'
event_lead_rule_id = fields.Many2one('event.lead.rule', string="Registration Rule", help="Rule that created this lead")
event_id = fields.Many2one('event.event', string="Source Event", help="Event triggering the rule that created this lead")
registration_ids = fields.Many2many(
'event.registration', string="Source Registrations",
groups='event.group_event_registration_desk',
help="Registrations triggering the rule that created this lead")
registration_count = fields.Integer(
string="# Registrations", compute='_compute_registration_count',
groups='event.group_event_registration_desk',
help="Counter for the registrations linked to this lead")
@api.depends('registration_ids')
def _compute_registration_count(self):
for record in self:
record.registration_count = len(record.registration_ids)
def _merge_dependences(self, opportunities):
super(Lead, self)._merge_dependences(opportunities)
# merge registrations as sudo, as crm people may not have access to event rights
self.sudo().write({
'registration_ids': [(4, registration.id) for registration in opportunities.sudo().registration_ids]
})
def _merge_get_fields(self):
return super(Lead, self)._merge_get_fields() + ['event_lead_rule_id', 'event_id']