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.

50 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Guewen Baconnier (Camptocamp SA)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from datetime import datetime, timedelta
  5. import openerp.tests.common as common
  6. class TestArchive(common.TransactionCase):
  7. def setUp(self):
  8. super(TestArchive, self).setUp()
  9. Partner = self.env['res.partner']
  10. self.partner1 = Partner.create(
  11. {'name': 'test user 1'})
  12. self.partner2 = Partner.create(
  13. {'name': 'test user 2'})
  14. self.partner3 = Partner.create(
  15. {'name': 'test user 3'})
  16. old_date = datetime.now() - timedelta(days=365)
  17. self.env.cr.execute(
  18. 'UPDATE res_partner SET write_date = %s '
  19. 'WHERE id IN %s', (old_date, tuple([self.partner2.id,
  20. self.partner3.id]))
  21. )
  22. self.Lifespan = self.env['record.lifespan']
  23. self.model_id = self.ref('base.model_res_partner')
  24. @common.at_install(False)
  25. @common.post_install(True)
  26. def test_lifespan(self):
  27. lifespan = self.Lifespan.create(
  28. {'model_id': self.model_id,
  29. 'months': 3,
  30. })
  31. lifespan.archive_records()
  32. self.assertTrue(self.partner1.active)
  33. self.assertFalse(self.partner2.active)
  34. self.assertFalse(self.partner3.active)
  35. @common.at_install(False)
  36. @common.post_install(True)
  37. def test_scheduler(self):
  38. self.Lifespan.create(
  39. {'model_id': self.model_id,
  40. 'months': 3,
  41. })
  42. self.Lifespan._scheduler_archive_records()
  43. self.assertTrue(self.partner1.active)
  44. self.assertFalse(self.partner2.active)
  45. self.assertFalse(self.partner3.active)