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

  1. # -*- coding: utf-8 -*-
  2. #
  3. #
  4. # Authors: Guewen Baconnier
  5. # Copyright 2015 Camptocamp SA
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. #
  21. from datetime import datetime, timedelta
  22. import openerp.tests.common as common
  23. class TestArchive(common.TransactionCase):
  24. def setUp(self):
  25. super(TestArchive, self).setUp()
  26. self.Partner = self.registry('res.partner')
  27. cr, uid = self.cr, self.uid
  28. self.partner1_id = self.Partner.create(cr, uid,
  29. {'name': 'test user 1'})
  30. self.partner2_id = self.Partner.create(cr, uid,
  31. {'name': 'test user 2'})
  32. self.partner3_id = self.Partner.create(cr, uid,
  33. {'name': 'test user 3'})
  34. old_date = datetime.now() - timedelta(days=365)
  35. self.cr.execute('UPDATE res_partner SET write_date = %s '
  36. 'WHERE id IN %s', (old_date, tuple([self.partner2_id,
  37. self.partner3_id]))
  38. )
  39. self.Lifespan = self.registry('record.lifespan')
  40. self.model_id = self.ref('base.model_res_partner')
  41. def test_lifespan(self):
  42. cr, uid = self.cr, self.uid
  43. lifespan_id = self.Lifespan.create(
  44. cr, uid,
  45. {'model_id': self.model_id,
  46. 'months': 3,
  47. })
  48. self.Lifespan.archive_records(cr, uid, [lifespan_id])
  49. self.assertTrue(self.Partner.browse(cr, uid, self.partner1_id).active)
  50. self.assertFalse(self.Partner.browse(cr, uid, self.partner2_id).active)
  51. self.assertFalse(self.Partner.browse(cr, uid, self.partner3_id).active)
  52. def test_scheduler(self):
  53. cr, uid = self.cr, self.uid
  54. self.Lifespan.create(
  55. cr, uid,
  56. {'model_id': self.model_id,
  57. 'months': 3,
  58. })
  59. self.Lifespan._scheduler_archive_records(cr, uid)
  60. self.assertTrue(self.Partner.browse(cr, uid, self.partner1_id).active)
  61. self.assertFalse(self.Partner.browse(cr, uid, self.partner2_id).active)
  62. self.assertFalse(self.Partner.browse(cr, uid, self.partner3_id).active)