Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
4408 Weergaven

I can install module already and i want to uninstall the module


I tried to use this:

boolean_field   = fields.Boolean('Install or Uninstall')

@api.onchange(' boolean_field ')
def install_module_secondary(self):
irModuleObj = self.env['ir.module.module']
irModuleObj.update_list()
moduleIds = irModuleObj.search(
[
('state', '!=', 'installed'),
('name', '=', 'module_name')
]
)

if moduleIds and self.boolean_field== True:
moduleIds[0].button_immediate_install()


@api.onchange(' boolean_field ')
def uninstall_module_secondary(self):
irModuleObj = self.env['ir.module.module']
irModuleObj.update_list()
moduleIdsUninstall = irModuleObj.search(
[
('state', '=', 'installed'),
('name', '=', 'module_name') 
]
)

if moduleIdsUninstall and self.boolean_field== False: 
moduleIdsUninstall[0].button_uninstall_wizard()


But it returns tuple index out of index then I removed the zero in uninstall then nothing happens, it just reload the page

Avatar
Annuleer
Beste antwoord

Hi,

Make sure that, the search returns a value. Because of the access rights, the search may return nothing, just ensure it by adding a print statement in the code.

I have tested the below code using the sudo and it seems working fine.

module_obj = self.env['ir.module.module']
module_obj.sudo().update_list()
# use sudo or set give access rights for user in corresponding group
module_rec = module_obj.search([('state', '!=', 'installed'),('shortdesc', '=', 'Lead to Issue')])
# make sure that search return result
module_rec.sudo().button_immediate_install()

Thanks

Avatar
Annuleer
Auteur

Dear Niyas,

Thank u sir, I got the problem solved.

Gerelateerde posts Antwoorden Weergaven Activiteit
1
mrt. 16
4347
1
mrt. 15
7682
2
dec. 18
7739
6
jul. 18
28313
2
jul. 17
5622