Skip to content

Commit

Permalink
[IMP] crm: add api.model_create_multi decorator on crm.lead
Browse files Browse the repository at this point in the history
  • Loading branch information
marielejeune committed Jan 3, 2023
1 parent 9d72ac1 commit 1a71cb3
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions addons/crm/models/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 1a71cb3

Please sign in to comment.