Ir al contenido
Menú
Se marcó esta pregunta
4645 Vistas

Hi Everyone,

I have been trying to automate module installation from a http controller. Installation of module has been succeeded and since accounting module has some wizards to be processed, they are not executed and they are in open state in "ir.actions.todo" table. So I took an example from addons/account/account_pre_install.yml and modified it accordingly. The problem is, the "write" method on ir.actions.todo model is not working and "create" and "execute_simple" methods on "account.installer" model are not working

Here is the whole code for that particular controller.

@http.route('/saas_worker/module', type="json", auth="none")

def check_module(self, fields):

    params = dict(map(operator.itemgetter('name', 'value'), fields))

     super_admin_password = config.get("admin_passwd")

     response_data = {}

         create_attrs = (

         super_admin_password,

         params["db_name"],

         False,

         params["db_lang"],

         params["create_admin_password"]

     ) 

db_created = request.session.proxy("db").create_database(*create_attrs)

if db_created:

    db = openerp.sql_db.db_connect(params["db_name"])

    with closing(db.cursor()) as cr:

        registry = openerp.modules.registry.RegistryManager.new(cr.dbname, update_module=True)

        ir_module = registry['ir.module.module']

        ir_model_data = registry['ir.model.data']

        wizards = registry['ir.actions.todo']

        res_partner = registry['res.partner']

        account_installer = registry['account.installer']

        selected_modules = params["modules"].split(",")

        module_ids = ir_module.search(cr,SUPERUSER_ID,[('name','in',selected_modules)])

        #Install modules automatically

        ir_module.button_immediate_install(cr,SUPERUSER_ID,module_ids,None)

        wizard = wizards.browse(cr,SUPERUSER_ID,self.ref(cr, SUPERUSER_ID,   ir_model_data,'account.account_configuration_installer_todo'))

        if wizard.state=='open':

            mod='l10n_us'

            ids = ir_module.search(cr, SUPERUSER_ID, [ ('name','=',mod) ], context=None)

            if ids:

                 wizards.write(cr, SUPERUSER_ID, self.ref(cr, SUPERUSER_ID,                     ir_model_data,'account.account_configuration_installer_todo'), {

                    'state': 'done'

                     })

                 wizard_id = account_installer.create(cr, SUPERUSER_ID, {

                     'charts': mod

                 })

                 account_installer.execute_simple(cr, SUPERUSER_ID, [wizard_id])

                 ir_module.state_update(cr, SUPERUSER_ID, ids,'to install', ['uninstalled'], context=None)

                 response_data["status"] = "ok"

                 response = json.dumps(response_data)

                 return response


def ref(self, cr, uid, registry_obj, external_id):

      return registry_obj.xmlid_to_res_id(cr, uid, external_id, raise_if_not_found=True)

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
jun 25
2061
0
may 24
1390
1
mar 24
1267
1
ene 24
1257
1
oct 22
2349