Skip to content

Instantly share code, notes, and snippets.

@mao-odoo
Last active February 16, 2022 15:10
Show Gist options
  • Save mao-odoo/0f68fc35e1f4cf8437e5d4b7a8607cb5 to your computer and use it in GitHub Desktop.
Save mao-odoo/0f68fc35e1f4cf8437e5d4b7a8607cb5 to your computer and use it in GitHub Desktop.

Create a server action record that allows user to uninstall many apps at once

Action Name

Uninstall Modules

Model

Module (type ir_module to get to the right one)

Action to do

Execute Python code

Python code

failed, success, already_done = [], [], []
for r in records:
  if r.state == "installed":
    try:
      r.button_immediate_uninstall()
      env.cr.commit()
    except:
      failed.append(r)
    else:
      success.append(r)
  else:
    already_done.append(r)

failed_txt = "the following modules failed to be uninstalled : %s \n" % ', '.join(m.name for m in failed)
success_txt = "the following modules succeeded to be uninstalled : %s \n" % ', '.join(m.name for m in success)
already_done_txt = "the following modules where already uninstalled when their turn came : %s \n" % ', '.join(m.name for m in already_done)
raise UserError(failed_txt + success_txt +already_done_txt  + "\n\n Maybe try again the failed ones ?")
      

Then click "CREATE CONTEXTUAL ACTION"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment