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.

87 lines
3.0 KiB

  1. # Copyright 2014-2016 Therp BV <http://therp.nl>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. # pylint: disable=consider-merging-classes-inherited
  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.models.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. IrModule = self.env['ir.module.module']
  57. for module in IrModule.search(
  58. [
  59. ('to_buy', '=', False),
  60. ('name', '!=', 'studio_customization')
  61. ]
  62. ):
  63. if get_module_path(module.name, display_warning=False):
  64. continue
  65. if module.state == 'uninstalled':
  66. self.env['cleanup.purge.line.module'].create({
  67. 'name': module.name,
  68. }).purge()
  69. continue
  70. res.append((0, 0, {'name': module.name}))
  71. if not res:
  72. raise UserError(_('No modules found to purge'))
  73. return res
  74. purge_line_ids = fields.One2many(
  75. 'cleanup.purge.line.module', 'wizard_id', 'Modules to purge')