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