From 1a71cb3c3ea3f222977cb676daf7243474d2cce0 Mon Sep 17 00:00:00 2001 From: mle Date: Tue, 27 Dec 2022 13:43:16 +0100 Subject: [PATCH] [IMP] crm: add api.model_create_multi decorator on crm.lead --- addons/crm/models/crm_lead.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 417a94f3bd261..ce34c73ce4b12 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -299,26 +299,34 @@ def name_create(self, name): self.browse(res[0])._onchange_stage_id() return res - @api.model - def create(self, vals): + @api.model_create_multi + def create(self, vals_list): + new_vals_list = [] + if isinstance(vals_list, dict): + vals_list = [vals_list] + context = dict(self._context or {}) + if not vals_list: + return super(Lead, self.with_context(context, mail_create_nolog=True)).create(vals_list) + vals = vals_list[0] # set up context used to find the lead's Sales Team which is needed # to correctly set the default stage_id - context = dict(self._context or {}) if vals.get('type') and not self._context.get('default_type'): context['default_type'] = vals.get('type') if vals.get('team_id') and not self._context.get('default_team_id'): context['default_team_id'] = vals.get('team_id') - if vals.get('user_id') and 'date_open' not in vals: - vals['date_open'] = fields.Datetime.now() - - partner_id = vals.get('partner_id') or context.get('default_partner_id') - onchange_values = self._onchange_partner_id_values(partner_id) - onchange_values.update(vals) # we don't want to overwrite any existing key - vals = onchange_values - + for vals in vals_list: + if vals.get('user_id') and 'date_open' not in vals: + vals['date_open'] = fields.Datetime.now() + + partner_id = vals.get('partner_id') or context.get('default_partner_id') + if partner_id: + onchange_values = self._onchange_partner_id_values(partner_id) + onchange_values.update(vals) # we don't want to overwrite any existing key + vals = onchange_values + new_vals_list.append(vals) # context: no_log, because subtype already handle this - return super(Lead, self.with_context(context, mail_create_nolog=True)).create(vals) + return super(Lead, self.with_context(context, mail_create_nolog=True)).create(new_vals_list) @api.multi def write(self, vals):