콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4842 화면

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)

아바타
취소
관련 게시물 답글 화면 활동
3
6월 25
2484
0
5월 24
1652
1
3월 24
1574
1
1월 24
1485
1
10월 22
2652