You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.8 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2014-2016 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import _, api, fields, models
  5. from odoo.exceptions import UserError
  6. from odoo.modules.module import get_module_path
  7. from odoo.addons.base.ir.ir_model import MODULE_UNINSTALL_FLAG
  8. class IrModelData(models.Model):
  9. _inherit = 'ir.model.data'
  10. @api.model
  11. def _module_data_uninstall(self, modules_to_remove):
  12. """this function crashes for xmlids on undefined models or fields
  13. referring to undefined models"""
  14. for this in self.search([('module', 'in', modules_to_remove)]):
  15. if this.model == 'ir.model.fields':
  16. field = self.env[this.model].with_context(
  17. **{MODULE_UNINSTALL_FLAG: True}).browse(this.res_id)
  18. if not field.exists() or field.model not in self.env:
  19. this.unlink()
  20. continue
  21. if this.model not in self.env:
  22. this.unlink()
  23. return super(IrModelData, self)._module_data_uninstall(
  24. modules_to_remove)
  25. class CleanupPurgeLineModule(models.TransientModel):
  26. _inherit = 'cleanup.purge.line'
  27. _name = 'cleanup.purge.line.module'
  28. wizard_id = fields.Many2one(
  29. 'cleanup.purge.wizard.module', 'Purge Wizard', readonly=True)
  30. @api.multi
  31. def purge(self):
  32. """
  33. Uninstall modules upon manual confirmation, then reload
  34. the database.
  35. """
  36. module_names = self.filtered(lambda x: not x.purged).mapped('name')
  37. modules = self.env['ir.module.module'].search([
  38. ('name', 'in', module_names)
  39. ])
  40. if not modules:
  41. return True
  42. self.logger.info('Purging modules %s', ', '.join(module_names))
  43. modules.filtered(
  44. lambda x: x.state not in ('uninstallable', 'uninstalled')
  45. ).button_immediate_uninstall()
  46. modules.refresh()
  47. modules.unlink()
  48. return self.write({'purged': True})
  49. class CleanupPurgeWizardModule(models.TransientModel):
  50. _inherit = 'cleanup.purge.wizard'
  51. _name = 'cleanup.purge.wizard.module'
  52. _description = 'Purge modules'
  53. @api.model
  54. def find(self):
  55. res = []
  56. for module in self.env['ir.module.module'].search([]):
  57. if get_module_path(module.name):
  58. continue
  59. if module.state == 'uninstalled':
  60. self.env['cleanup.purge.line.module'].create({
  61. 'name': module.name,
  62. }).purge()
  63. continue
  64. res.append((0, 0, {'name': module.name}))
  65. if not res:
  66. raise UserError(_('No modules found to purge'))
  67. return res
  68. purge_line_ids = fields.One2many(
  69. 'cleanup.purge.line.module', 'wizard_id', 'Modules to purge')