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.

71 lines
2.6 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. # Copyright 2017 Creu Blanca <https://creublanca.es/>
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  3. from odoo.tests import common
  4. from datetime import date
  5. class TestSequence(common.TransactionCase):
  6. def setUp(self):
  7. super().setUp()
  8. self.date = date(2018, 3, 14)
  9. def get_sequence(self, method):
  10. return self.env['ir.sequence'].create({
  11. 'name': 'Test sequence',
  12. 'implementation': 'standard',
  13. 'use_date_range': True,
  14. 'range_reset': method,
  15. 'padding': '5'
  16. })
  17. def test_none(self):
  18. sequence = self.get_sequence(False)
  19. self.assertFalse(sequence.date_range_ids)
  20. self.assertEqual('00001', sequence.with_context(
  21. ir_sequence_date=self.date).next_by_id())
  22. range = sequence.date_range_ids
  23. self.assertTrue(range)
  24. self.assertEqual(date(2018, 1, 1), range.date_from)
  25. self.assertEqual(date(2018, 12, 31), range.date_to)
  26. def test_daily(self):
  27. sequence = self.get_sequence('daily')
  28. self.assertFalse(sequence.date_range_ids)
  29. self.assertEqual('00001', sequence.with_context(
  30. ir_sequence_date=self.date).next_by_id())
  31. range = sequence.date_range_ids
  32. self.assertTrue(range)
  33. self.assertEqual(self.date, range.date_from)
  34. self.assertEqual(self.date, range.date_to)
  35. def test_weekly(self):
  36. sequence = self.get_sequence('weekly')
  37. self.assertFalse(sequence.date_range_ids)
  38. self.assertEqual('00001', sequence.with_context(
  39. ir_sequence_date=self.date).next_by_id())
  40. range = sequence.date_range_ids
  41. self.assertTrue(range)
  42. self.assertEqual(date(2018, 3, 12), range.date_from)
  43. self.assertEqual(date(2018, 3, 18), range.date_to)
  44. def test_monthly(self):
  45. sequence = self.get_sequence('monthly')
  46. self.assertFalse(sequence.date_range_ids)
  47. self.assertEqual('00001', sequence.with_context(
  48. ir_sequence_date=self.date).next_by_id())
  49. range = sequence.date_range_ids
  50. self.assertTrue(range)
  51. self.assertEqual(date(2018, 3, 1), range.date_from)
  52. self.assertEqual(date(2018, 3, 31), range.date_to)
  53. def test_yearly(self):
  54. sequence = self.get_sequence('yearly')
  55. self.assertFalse(sequence.date_range_ids)
  56. self.assertEqual('00001', sequence.with_context(
  57. ir_sequence_date=self.date).next_by_id())
  58. range = sequence.date_range_ids
  59. self.assertTrue(range)
  60. self.assertEqual(date(2018, 1, 1), range.date_from)
  61. self.assertEqual(date(2018, 12, 31), range.date_to)