'Check the write_expression and update crud_model_id accordingly'

@api.onchange('write_expression')
def _onchange_write_expression(self):

    values = {}
    if self.write_expression:
        (valid, model_name, message) = self._check_expression(self.write_expression, self.model_id)
    else:
        (valid, model_name, message) = (True, None, False)
        if self.model_id:
            model_name = self.model_id.model
    if (not valid):
        return {'warning': {'title': _('Incorrect    expression'), 'message': (message or _('Invalid    expression'))}}
    if model_name:
        self.crud_model_id = self.env['ir.model'].search([('model', '=', model_name)])
