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.

62 lines
1.9 KiB

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