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.

49 lines
2.0 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. """Set modules to upgrade searching by their dir checksum."""
  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(self):
  19. """Make a fully automated addon upgrade."""
  20. # Compute updates by checksum when called in @api.model fashion
  21. if not self:
  22. self.get_module_list()
  23. Module = self.env["ir.module.module"]
  24. # Get every addon state before updating
  25. pre_states = {addon["name"]: addon["state"]
  26. for addon in Module.search_read([], ["name", "state"])}
  27. # Perform upgrades, possibly in a limited graph that excludes me
  28. result = super(ModuleUpgrade, self).upgrade_module()
  29. # Reload environments, anything may have changed
  30. self.env.clear()
  31. # Update addons checksum if state changed and I wasn't uninstalled
  32. own = Module.search_read(
  33. [("name", "=", "module_auto_update")],
  34. ["state"],
  35. limit=1)
  36. if own and own[0]["state"] != "uninstalled":
  37. for addon in Module.search([]):
  38. if addon.state != pre_states.get(addon.name):
  39. # Trigger the write hook that should have been
  40. # triggered when the module was [un]installed/updated in
  41. # the limited module graph inside above call to super(),
  42. # and updates its dir checksum as needed
  43. addon.latest_version = addon.latest_version
  44. return result