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.5 KiB

6 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. from odoo import api, SUPERUSER_ID
  20. from . import models
  21. def _get_value(env, model):
  22. model_model = env['ir.model']
  23. model_fields = env['ir.model.fields']
  24. model = model_model.search([('model', '=', model)], limit=1)
  25. if model.exists():
  26. field_domain = [
  27. ('model_id', '=', model.id),
  28. ('ttype', '=', 'datetime'),
  29. ('name', '=', 'create_date')]
  30. field = model_fields.search(field_domain, limit=1)
  31. return model, field
  32. return None
  33. def _init_default_rules(cr, registry):
  34. env = api.Environment(cr, SUPERUSER_ID, {})
  35. rule = env['muk_autovacuum.rules']
  36. values = _get_value(env, 'mail.message')
  37. if values:
  38. rule.create({
  39. 'name': "Delete Message Attachments after 6 Months",
  40. 'model': values[0].id,
  41. 'active': False,
  42. 'state': 'time',
  43. 'time_field': values[1].id,
  44. 'time_type': 'months',
  45. 'time': 6,
  46. 'only_attachments': True})
  47. rule.create({
  48. 'name': "Delete Messages after 1 Year",
  49. 'model': values[0].id,
  50. 'active': False,
  51. 'state': 'time',
  52. 'time_field': values[1].id,
  53. 'time_type': 'years',
  54. 'time': 1})
  55. values = _get_value(env, 'ir.logging')
  56. if values:
  57. rule.create({
  58. 'name': "Delete Logs after 2 Weeks",
  59. 'model': values[0].id,
  60. 'active': False,
  61. 'state': 'time',
  62. 'time_field': values[1].id,
  63. 'time_type': 'weeks',
  64. 'time': 2,
  65. 'protect_starred': False})