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.

61 lines
1.9 KiB

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. class Module(models.Model):
  5. _inherit = 'ir.module.module'
  6. checksum_dir = fields.Char(
  7. compute='_compute_checksum_dir',
  8. )
  9. checksum_installed = fields.Char(
  10. compute='_compute_checksum_installed',
  11. inverse='_inverse_checksum_installed',
  12. store=False,
  13. )
  14. @api.depends('name')
  15. def _compute_checksum_dir(self):
  16. for rec in self:
  17. rec.checksum_dir = rec._get_checksum_dir()
  18. def _compute_checksum_installed(self):
  19. saved_checksums = self._get_saved_checksums()
  20. for rec in self:
  21. rec.checksum_installed = saved_checksums.get(rec.name, False)
  22. def _inverse_checksum_installed(self):
  23. saved_checksums = self._get_saved_checksums()
  24. for rec in self:
  25. saved_checksums[rec.name] = rec.checksum_installed
  26. self._save_installed_checksums()
  27. @api.multi
  28. def _store_checksum_installed(self, vals):
  29. """Store the right installed checksum, if addon is installed."""
  30. if 'checksum_installed' not in vals:
  31. try:
  32. version = vals["latest_version"]
  33. except KeyError:
  34. return # Not [un]installing/updating any addon
  35. if version is False:
  36. # Uninstalling
  37. self.write({'checksum_installed': False})
  38. else:
  39. # Installing or updating
  40. for one in self:
  41. one.checksum_installed = one.checksum_dir
  42. @api.model
  43. def create(self, vals):
  44. res = super(Module, self).create(vals)
  45. res._store_checksum_installed(vals)
  46. return res
  47. @api.multi
  48. def write(self, vals):
  49. res = super(Module, self).write(vals)
  50. self._store_checksum_installed(vals)
  51. return res