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.

46 lines
1.7 KiB

8 years ago
8 years ago
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
  4. from odoo import api, models
  5. class ModuleUpgrade(models.TransientModel):
  6. _inherit = 'base.module.upgrade'
  7. @api.model
  8. def get_module_list(self):
  9. if not self.env.context.get('module_uninstall'):
  10. Module = self.env["ir.module.module"]
  11. installed_modules = Module.search([('state', '=', 'installed')])
  12. upgradeable_modules = installed_modules.filtered(
  13. lambda r: r.checksum_dir != r.checksum_installed,
  14. )
  15. upgradeable_modules.button_upgrade()
  16. return super(ModuleUpgrade, self).get_module_list()
  17. @api.multi
  18. def upgrade_module_cancel(self):
  19. return super(
  20. ModuleUpgrade,
  21. self.with_context(retain_checksum_installed=True),
  22. ).upgrade_module_cancel()
  23. @api.multi
  24. def upgrade_module(self):
  25. # Compute updates by checksum when called in @api.model fashion
  26. if not self:
  27. self.get_module_list()
  28. # Get base adddon status before updating
  29. base = self.env["ir.module.module"].search([("name", "=", "base")])
  30. pre_state = base.state
  31. result = super(ModuleUpgrade, self).upgrade_module()
  32. # Update base addon checksum if its state changed
  33. base.invalidate_cache()
  34. if base.state != pre_state:
  35. # This triggers the write hook that should have been triggered
  36. # when the module was [un]installed/updated in the base-only
  37. # module graph inside above call to super(), and updates its
  38. # dir checksum as needed
  39. base.latest_version = base.latest_version
  40. return result