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.

66 lines
2.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo.tests.common import TransactionCase
  5. from odoo import fields
  6. class TestIrSequenceDateRange(TransactionCase):
  7. """
  8. Tests for ir.sequence.date_range
  9. """
  10. def setUp(self):
  11. super(TestIrSequenceDateRange, self).setUp()
  12. self.sequence = self.env.ref(
  13. "sequence_date_range.ir_sequence_demo")
  14. def _get_current_date_range(self, sequence=False):
  15. """
  16. Get the sequence date range related to the current date
  17. :param sequence: ir.sequence recordset
  18. :return: ir.sequence.date_range recordset
  19. """
  20. sequence = sequence or self.sequence
  21. today = fields.Date.today()
  22. if self.env.context.get('ir_sequence_date'):
  23. today = self.env.context.get('ir_sequence_date')
  24. seq_date = self.env['ir.sequence.date_range'].search([
  25. ('sequence_id', '=', sequence.id),
  26. ('date_from', '<=', today),
  27. ('date_to', '>=', today),
  28. ], limit=1)
  29. return seq_date
  30. def test_using_date_range1(self):
  31. """
  32. Test the date range sequence.
  33. Check if the date (used into the generated sequence) is the one set
  34. into the date_to field (instead of date_from)
  35. :return:
  36. """
  37. self.assertEquals(self.sequence.date_range_field, 'date_to')
  38. current_date_range = self._get_current_date_range()
  39. date_to = fields.Date.from_string(current_date_range.date_to)
  40. value = self.sequence._next()
  41. expected_str = date_to.strftime("%Y-%m-%d")
  42. self.assertIn(expected_str, value)
  43. return
  44. def test_using_date_range2(self):
  45. """
  46. Test the date range sequence.
  47. Check if the date (used into the generated sequence) is the one set
  48. into the date_from field
  49. :return:
  50. """
  51. self.sequence.write({
  52. 'date_range_field': 'date_from',
  53. })
  54. self.assertEquals(self.sequence.date_range_field, 'date_from')
  55. current_date_range = self._get_current_date_range()
  56. date_from = fields.Date.from_string(current_date_range.date_from)
  57. value = self.sequence._next()
  58. expected_str = date_from.strftime("%Y-%m-%d")
  59. self.assertIn(expected_str, value)
  60. return