Hi there,
I have a model event_mgmt that inherits from crm.lead. We would like to create a reminder (mail.activity) as a result of a change in the stage_id.
@api.model
def _onchange_stage_id_values(self, stage_id):
""" returns the new values when stage_id has changed """
if not stage_id:
return {}
stage = self.env['crm.stage'].browse(stage_id)
if stage.on_change:
return {'probability': stage.probability}
return {}
@api.onchange('stage_id')
def _onchange_stage_id(self):
values = self._onchange_stage_id_values(self.stage_id.id)
event_user_id = self.user_id
self.update(values)
if self.stage_id.id == 3:
self = self.env['event_mgmt.event_mgmt'].browse(self._origin.id)
activity = self.env['mail.activity']
activity_ins = activity.create(
{'res_id': self.id,
'res_model_id': 170,
'res_model':'event_mgmt.event_mgmt',
'activity_type_id':2,
'summary': 'Follow Up',
'note':'Han pasado 5 días desde el paso a propuesta. Realizar seguimiento a la propuesta enviada.',
'date_deadline': date.today() + timedelta(days=5),
'activity_category':'default',
'previous_activity_type_id': False,
'recommended_activity_type_id': False,
'user_id': self.user_id.id
})
Apparently the mail.activity record is created but I get an error in the console becuse there is an attempt of updating the same event_mgmt but with all its fields but the dates empty, obviously it fails.
The error:
2019-06-13 18:30:34,698 5544 ERROR Yimby_GestionComercialEventos_v0.63 odoo.sql_db: bad query: b'UPDATE "event_mgmt_event_mgmt" SET "venue_id"=NULL,"active"=false,"team_id"=NULL,"partner_id"=NULL,"assembly_finish_time"=NULL,"date_closed"=\'2019-06-13 18:30:34\',"activity"=false,"assembly_start_time"=NULL,"attendants"=0,"timing_notes"=NULL,"general_notes"=NULL,"event_finish_time"=NULL,"user_id"=NULL,"photographer_note"=NULL,"activity_note"=NULL,"email_from"=NULL,"priority"=NULL,"date_last_stage_update"=\'2019-06-13 18:30:34\',"stage_id"=NULL,"event_start_time"=NULL,"dj_note"=NULL,"name"=NULL,"photographer"=false,"probability"=0.0,"write_uid"=1,"write_date"=(now() at time zone \'UTC\') WHERE id IN (2)'
ERROR: el valor null para la columna «name» viola la restricción not null
DETAIL: La fila que falla contiene (2, null, 0, null, null, null, null, null, null, null, 1970, null, null, f, null, f, null, f, null, null, null, null, f, null, null, null, null, null, null, 2019-02-17 22:18:17.975986, 2019-06-13 16:30:34.547321, null, null, f, opportunity, null, 2019-06-13 18:30:34, null, null, null, 2019-02-17 23:18:17, 0, 0, 2019-06-13 18:30:34, null, 0, 0, null, null, 3, null, null, null, null, null, null, null, null, null, null, 1, null, null, null, null, 1, 1, null, null, null, null, null, null, 0, 0, 0, null, null, null).
I don't get why the very same record is updated with null values, Any clue? I'm pretty sure I'm missing something and any help would be very welcome.
Thank you in advance,