示例#1
0
 def update_module(self, db_name, module, rel_id=False):
     """
         Actualiza un modulo sobre la base de datos
     """
     # Crea un nuevo registro
     db = ws()
     context={}
     uid = 1
     mod_obj = self.pool.get('ir.module.module')
     data_obj = self.pool.get('ir.model.data')
     mod_rel_obj = self.pool.get('admon.database.module.relation')
     # Valida que exista la base de datos
     db_exist = db.exp_db_exist(db_name)
     if db_exist == False:
         raise osv.except_osv(_('Error!'),_("la base de datos que intenta modificar no existe '%s'")%(db_name,))
     
     db = sql_db.db_connect(db_name)
     cr = db.cursor()
     cr.autocommit(True) # avoid transaction block
     try:
         # Revisa si el modulo existe en la base de datos
         mod_ids = mod_obj.search(cr, uid, [('name','=',module)], context=context)
         if mod_ids:
             # Revisa si el modulo esta instalado
             mod = mod_obj.browse(cr, uid, mod_ids[0], context=context)
             print "************ update modules ********** ",db_name, " - ", module, " - ", mod.state
             if mod.state == 'installed':
                 print "********** update ", db_name, " ************** ", module
                 mod_obj.button_immediate_upgrade(cr, uid, [mod.id], context=context)
             elif mod.state == 'to_install':
                 print "********** to install ", db_name, " ************** ", module
                 mod.obj.button_install_cancel(cr, uid, [mod.id], context=context)
                 mod_obj.button_immediate_install(cr, uid, [mod.id], context=context)
             elif mod.state == 'uninstalled':
                 print "********** install ", db_name, "  ************* ", module
                 mod_obj.button_immediate_install(cr, uid, [mod.id], context=context)
             elif mod.state == 'to_upgrade':
                 print "********** to upgrade ", db_name, " ************** ", module
                 mod.obj.button_upgrade_cancel(cr, uid, [mod.id], context=context)
                 mod_obj.button_immediate_upgrade(cr, uid, [mod.id], context=context)
             else:
                 # Si ocurre un error pone el modulo como cancelado
                 mod.obj.button_upgrade_cancel(cr, uid, [mod.id], context=context)
                 # Pone el campo de 
                 if rel_id:
                     update_date = time.strftime('%Y-%m-%d %H:%M:%S')
                     mod_rel_obj.write(cr, uid, [rel_id], {'state':'noupdated', 'date_update':update_date})
                 print "*********** error de instalacion de modulo ************* "
                 raise osv.except_osv(_('Error!'),_("No se pudo instalar el modulo '%s' en la base de datos '%s', realice el proceso directo de la base de datos")%(module,db_name))
     finally:
         #print "************* finaliza conexion - ", db_name, " *************** "
         cr.close()
         #sql_db.close_db(db_name)
     return True
 def _get_method_db_selection(self, cr, uid, context=None):
     # From module of PAC inherit this function and add new methods
     db_list = []
     result = []
     db = ws()
     res = []
     # Obtiene la lista de
     db_list = db.exp_list()
     for db in db_list:
         res.append((db, ' %s ' % (db, )))
     result.extend(res)
     return result