'Clear records removed from updated module data.
This method is called at the end of the module loading process.
It is meant to removed records that are no longer present in the
updated data. Such records are recognised as the one with an xml id
and a module in ir_model_data and noupdate set to false, but not
present in self.loads.'

@api.model
def _process_end(self, modules):

    if ((not modules) or tools.config.get('import_partial')):
        return True
    bad_imd_ids = []
    self = self.with_context({MODULE_UNINSTALL_FLAG: True})
    query = '    SELECT    id,    name,    model,    res_id,    module    FROM    ir_model_data\n                                                                                WHERE    module    IN    %s    AND    res_id    IS    NOT    NULL    AND    noupdate=%s    ORDER    BY    id    DESC\n                                                                '
    self._cr.execute(query, (tuple(modules), False))
    for (id, name, model, res_id, module) in self._cr.fetchall():
        if ((module, name) not in self.loads):
            if (model in self.env):
                _logger.info('Deleting    %s@%s    (%s.%s)', res_id, model, module, name)
                record = self.env[model].browse(res_id)
                if record.exists():
                    record.unlink()
                else:
                    bad_imd_ids.append(id)
    if bad_imd_ids:
        self.browse(bad_imd_ids).unlink()
    self.loads.clear()
