如何在不输入图表帐户初始化向导的数据的情况下自动安装会计科目表?

时间:2015-11-25 06:40:15

标签: openerp

我一直在尝试从http控制器自动化模块安装。模块的安装已经成功,并且由于会计模块有一些要处理的向导,它们不会被执行,并且它们在ir.actions.todo表中处于打开状态。所以我从addons/account/account_pre_install.yml中提取了一个示例并对其进行了相应的修改。问题是,write模型上的ir.actions.todo方法无效,create模型上的execute_simpleaccount.installer方法无效。

以下是该特定控制器的完整代码。

@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)

0 个答案:

没有答案