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.

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