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
  1. ###################################################################################
  2. #
  3. # Copyright (C) 2018 MuK IT GmbH
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. ###################################################################################
  19. import logging
  20. from odoo import api, models, fields
  21. from odoo.addons.muk_fields_lobject.fields import LargeObject
  22. _logger = logging.getLogger(__name__)
  23. class Store(models.Model):
  24. _name = 'muk_converter.store'
  25. _description = 'Converter Store'
  26. name = fields.Char(
  27. compute="_compute_name",
  28. string="Name",
  29. store=True)
  30. used_date = fields.Date(
  31. string="Used on",
  32. default=fields.Datetime.now)
  33. checksum = fields.Char(
  34. string="Checksum",
  35. required=True)
  36. format = fields.Char(
  37. string="Format",
  38. required=True)
  39. content_fname = fields.Char(
  40. string="Filename",
  41. required=True)
  42. content = LargeObject(
  43. string="Data",
  44. required=True)
  45. @api.depends('checksum', 'content_fname')
  46. def _compute_name(self):
  47. for record in self:
  48. record.name = "%s (%s)" % (record.content_fname, record.checksum)
  49. @api.model
  50. def garbage_collector(self):
  51. param = self.env['ir.config_parameter'].sudo()
  52. max_store = param.get_param("muk_converter.max_store", default=20)
  53. records = self.search([], order='used_date asc')
  54. if len(records) > int(max_store):
  55. records[max_store:].unlink()