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.

68 lines
2.1 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. # Copyright 2017 LasLabs Inc.
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
  3. from odoo import api, fields, models
  4. PARAM_DEPRECATED = "module_auto_update.enable_deprecated"
  5. class Module(models.Model):
  6. _inherit = 'ir.module.module'
  7. checksum_dir = fields.Char(
  8. deprecated=True,
  9. compute='_compute_checksum_dir',
  10. )
  11. checksum_installed = fields.Char(
  12. deprecated=True,
  13. compute='_compute_checksum_installed',
  14. inverse='_inverse_checksum_installed',
  15. store=False,
  16. )
  17. @api.depends('name')
  18. def _compute_checksum_dir(self):
  19. for rec in self:
  20. rec.checksum_dir = rec._get_checksum_dir()
  21. def _compute_checksum_installed(self):
  22. saved_checksums = self._get_saved_checksums()
  23. for rec in self:
  24. rec.checksum_installed = saved_checksums.get(rec.name, False)
  25. def _inverse_checksum_installed(self):
  26. checksums = self._get_saved_checksums()
  27. for rec in self:
  28. checksums[rec.name] = rec.checksum_installed
  29. self._save_checksums(checksums)
  30. @api.multi
  31. def _store_checksum_installed(self, vals):
  32. """Store the right installed checksum, if addon is installed."""
  33. if not self.env["base.module.upgrade"]._autoupdate_deprecated():
  34. # Skip if deprecated features are disabled
  35. return
  36. if 'checksum_installed' not in vals:
  37. try:
  38. version = vals["latest_version"]
  39. except KeyError:
  40. return # Not [un]installing/updating any addon
  41. if version is False:
  42. # Uninstalling
  43. self.write({'checksum_installed': False})
  44. else:
  45. # Installing or updating
  46. for one in self:
  47. one.checksum_installed = one.checksum_dir
  48. @api.model
  49. def create(self, vals):
  50. res = super(Module, self).create(vals)
  51. res._store_checksum_installed(vals)
  52. return res
  53. @api.multi
  54. def write(self, vals):
  55. res = super(Module, self).write(vals)
  56. self._store_checksum_installed(vals)
  57. return res