# -*- coding: utf-8 -*-
##############################################################################
#
#    Author: Guewen Baconnier
#    Copyright 2012-2013 Camptocamp SA
#    Copyright 2015 anybox SA
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp import models, api
from openerp.tools.cache import ormcache
import threading


class IrModuleModule(models.Model):
    """Overwrite ir.module.module to add cached method 'is_module_installed'.
    This method is cached, because connector will always check if a module is
    installed before do action.

    All update (write method) on the field state, invalidate the cache
    """
    _inherit = 'ir.module.module'

    @ormcache(skiparg=1)
    def is_module_installed(self, module_name):
        states = ['installed', 'to upgrade']
        if getattr(threading.currentThread(), 'testing', False):
            # In the case of the test is doing during the installation,
            # then state of the module connector is 'to install'
            states.append('to install')

        return bool(len(self.search([('name', '=', module_name),
                                     ('state', 'in', states)])))

    @api.multi
    def write(self, values):
        res = super(IrModuleModule, self).write(values)
        if 'state' in values:
            self.clear_caches()

        return res

@@ -1043,25 +1043,8 @@
 che%0A
-import threading%0A
 %0A%0Acl
@@ -1470,17 +1470,17 @@
 tates = 
-%5B
+(
 'install
@@ -1500,252 +1500,9 @@
 ade'
-%5D%0A        if getattr(threading.currentThread(), 'testing', False):%0A            # In the case of the test is doing during the installation,%0A            # then state of the module connector is 'to install'%0A            states.append('to install')%0A
+)
 %0A   

Remove useless trick in is_module_installed