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.

46 lines
1.9 KiB

  1. # Copyright 2019 Eficent Business and IT Consulting Services S.L.
  2. # (http://www.eficent.com)
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from datetime import datetime, timedelta
  5. import odoo.tests.common as common
  6. class TestResourceCalendarScheduleIteration(common.TransactionCase):
  7. def setUp(self):
  8. super(TestResourceCalendarScheduleIteration, self).setUp()
  9. self.icp = self.env['ir.config_parameter']
  10. self.calendar = self.env.ref('resource.resource_calendar_std')
  11. self.icp.set_param(
  12. "resource.calendar.schedule.days.iteration.limit", 200)
  13. def test_01_days_iteration(self):
  14. days = 150
  15. calendar_day = self.calendar.plan_days(-1 * days - 1, datetime.today())
  16. aprox_date = datetime.today() - timedelta(days=days)
  17. # Without more iteration limit the date returned will be only 100
  18. # days back using calendar (default iteration limit) instead of 150.
  19. self.assertLess(calendar_day, aprox_date)
  20. def test_02_hours_iteration(self):
  21. hours = 1500 * 8
  22. hours_2 = 1700 * 8
  23. limit_hour = self.calendar.plan_hours(-1 * hours - 1, datetime.today())
  24. limit_hour_2 = self.calendar.plan_hours(
  25. -1 * hours_2 - 1, datetime.today())
  26. # Both hour computation exceeded the limit so they should be the
  27. # same (which is incorrect).
  28. self.assertEqual(limit_hour, limit_hour_2)
  29. self.icp.set_param(
  30. "resource.calendar.schedule.hours.iteration.limit", 2000)
  31. correct_hour = self.calendar.plan_hours(
  32. -1 * hours - 1, datetime.today())
  33. correct_hour_2 = self.calendar.plan_hours(
  34. -1 * hours_2 - 1, datetime.today())
  35. self.assertNotEqual(correct_hour, correct_hour_2)
  36. self.assertLess(correct_hour, limit_hour)
  37. self.assertLess(correct_hour_2, limit_hour_2)