'Set the \'clear\' state to defined fields'

@api.multi
def reverse_anonymize_database(self):

    self.ensure_one()
    IrModelFieldsAnonymization = self.env['ir.model.fields.anonymization']
    state = IrModelFieldsAnonymization._get_global_state()
    if (state == 'clear'):
        raise UserError(_('The    database    is    not    currently    anonymized,    you    cannot    reverse    the    anonymization.'))
    elif (state == 'unstable'):
        raise UserError(_('The    database    anonymization    is    currently    in    an    unstable    state.    Some    fields    are    anonymized,    while    some    fields    are    not    anonymized.    You    should    try    to    solve    this    problem    before    trying    to    do    anything.'))
    if (not self.file_import):
        raise UserError(('%s:    %s' % (_('Error    !'), _('It    is    not    possible    to    reverse    the    anonymization    process    without    supplying    the    anonymization    export    file.'))))
    data = pickle.loads(base64.decodestring(self.file_import))
    fixes = self.env['ir.model.fields.anonymization.migration.fix'].search_read([('target_version', '=', '.'.join(map(str, version_info[:2])))], ['model_name', 'field_name', 'query', 'query_type', 'sequence'])
    fixes = group(fixes, ('model_name', 'field_name'))
    for line in data:
        queries = []
        table_name = (self.env[line['model_id']]._table if (line['model_id'] in self.env) else None)
        key = (line['model_id'], line['field_id'])
        custom_updates = fixes.get(key)
        if custom_updates:
            custom_updates.sort(key=itemgetter('sequence'))
            queries = [(record['query'], record['query_type']) for record in custom_updates if record['query_type']]
        elif table_name:
            queries = [(('update    "%(table)s"    set    "%(field)s"    =    %%(value)s    where    id    =    %%(id)s' % {'table': table_name, 'field': line['field_id']}), 'sql')]
        for query in queries:
            if (query[1] == 'sql'):
                self.env.cr.execute(query[0], {'value': line['value'], 'id': line['id']})
            elif (query[1] == 'python'):
                safe_eval((query[0] % line))
            else:
                raise Exception(("Unknown    query    type    '%s'.    Valid    types    are:    sql,    python." % (query['query_type'],)))
    ano_fields = IrModelFieldsAnonymization.search([('state', '!=', 'not_existing')])
    ano_fields.write({'state': 'clear'})
    self.msg = '\n'.join(['Successfully    reversed    the    anonymization.', ''])
    history = self.env['ir.model.fields.anonymization.history'].create({'date': fields.Datetime.now(), 'field_ids': [[6, 0, ano_fields.ids]], 'msg': self.msg, 'filepath': False, 'direction': 'anonymized    ->    clear', 'state': 'done'})
    return {'res_id': self.id, 'view_id': self.env.ref('anonymization.view_ir_model_fields_anonymize_wizard_form').ids, 'view_type': 'form', 'view_mode': 'form', 'res_model': 'ir.model.fields.anonymize.wizard', 'type': 'ir.actions.act_window', 'context': {'step': 'just_desanonymized'}, 'target': 'new'}
