From a74a4bbfe7a5f36d553f79da0d79530e3ee9a49c Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Tue, 19 Mar 2019 10:11:41 +0100 Subject: [PATCH] [11.0] resourece_calendar_schedule_iteration: add tests and some minor corrections --- .../README.rst | 19 +++---- resource_calendar_schedule_iteration/hooks.py | 15 ++--- .../readme/CONTRIBUTORS.rst | 6 +- .../readme/DESCRIPTION.rst | 5 +- .../static/description/index.html | 55 +++++++++++++------ .../tests/__init__.py | 1 + ...st_resource_calendar_schedule_iteration.py | 46 ++++++++++++++++ 7 files changed, 104 insertions(+), 43 deletions(-) create mode 100644 resource_calendar_schedule_iteration/tests/__init__.py create mode 100644 resource_calendar_schedule_iteration/tests/test_resource_calendar_schedule_iteration.py diff --git a/resource_calendar_schedule_iteration/README.rst b/resource_calendar_schedule_iteration/README.rst index 62e67700e..20e9df858 100644 --- a/resource_calendar_schedule_iteration/README.rst +++ b/resource_calendar_schedule_iteration/README.rst @@ -14,10 +14,10 @@ Resource Calendar Schedule Iteration :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html :alt: License: LGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github - :target: https://github.com/OCA/server-tools/tree/11.0/resource_calendar_schedule_iterations + :target: https://github.com/OCA/server-tools/tree/11.0/resource_calendar_schedule_iteration :alt: OCA/server-tools .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/server-tools-11-0/server-tools-11-0-resource_calendar_schedule_iterations + :target: https://translation.odoo-community.org/projects/server-tools-11-0/server-tools-11-0-resource_calendar_schedule_iteration :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png :target: https://runbot.odoo-community.org/runbot/149/11.0 @@ -25,16 +25,13 @@ Resource Calendar Schedule Iteration |badge1| |badge2| |badge3| |badge4| |badge5| -When you want to plan a number of days in the past or in the future consiering +When you want to plan a number of days in the past or in the future considering a working calendar, Odoo limits the number of days/hours that you can plan ahead. In case that you want to plan days forward/backward, it currently restricts to 100 iterations. -In case that you want to plan hours forward/backward, it currently restricts -to 100 iterations. - This module allows you to increase the iteration limit used in the resource calendar to schedule days or hours by means of a system parameter defined by the administrator. @@ -59,7 +56,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -74,8 +71,10 @@ Authors Contributors ~~~~~~~~~~~~ -* Jordi Ballester Alomar - (https://www.eficent.com) +* Eficent (https://www.eficent.com) + + * Jordi Ballester Alomar + * Lois Rilo Antelo Maintainers ~~~~~~~~~~~ @@ -90,6 +89,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/server-tools `_ project on GitHub. +This module is part of the `OCA/server-tools `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/resource_calendar_schedule_iteration/hooks.py b/resource_calendar_schedule_iteration/hooks.py index a09a680c8..f8140501f 100644 --- a/resource_calendar_schedule_iteration/hooks.py +++ b/resource_calendar_schedule_iteration/hooks.py @@ -1,22 +1,15 @@ # Copyright 2019 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -import pytz import datetime from datetime import timedelta from odoo.addons.resource.models.resource import ResourceCalendar +from odoo.addons.resource.models.resource import to_naive_user_tz from odoo.tools.float_utils import float_compare -def to_naive_user_tz(datetime, record): - tz_name = record._context.get('tz') or record.env.user.tz - tz = tz_name and pytz.timezone(tz_name) or pytz.UTC - return pytz.UTC.localize(datetime.replace( - tzinfo=None), is_dst=False).astimezone(tz).replace(tzinfo=None) - - def post_load_hook(): def _new_schedule_days(self, days, day_dt, compute_leaves=False, @@ -79,7 +72,7 @@ def post_load_hook(): # HOOK. Use the iterations_limit here while float_compare(remaining_hours, 0.0, precision_digits=2) in ( - 1, 0) and iterations < 1000: + 1, 0) and iterations < iterations_limit: if backwards: call_args['end_time'] = current_datetime.time() else: @@ -117,10 +110,10 @@ def post_load_hook(): ResourceCalendar._schedule_days_original = \ ResourceCalendar._schedule_days - ResourceCalendar._schedule_days = _new_schedule_days + ResourceCalendar._patch_method("_schedule_days", _new_schedule_days) if not hasattr(ResourceCalendar, '_schedule_hours_original'): ResourceCalendar._schedule_hours_original = \ ResourceCalendar._schedule_hours - ResourceCalendar._schedule_hours = _new_schedule_hours + ResourceCalendar._patch_method("_schedule_hours", _new_schedule_hours) diff --git a/resource_calendar_schedule_iteration/readme/CONTRIBUTORS.rst b/resource_calendar_schedule_iteration/readme/CONTRIBUTORS.rst index 2c7d5869b..149826cd3 100644 --- a/resource_calendar_schedule_iteration/readme/CONTRIBUTORS.rst +++ b/resource_calendar_schedule_iteration/readme/CONTRIBUTORS.rst @@ -1,2 +1,4 @@ -* Jordi Ballester Alomar - (https://www.eficent.com) +* Eficent (https://www.eficent.com) + + * Jordi Ballester Alomar + * Lois Rilo Antelo diff --git a/resource_calendar_schedule_iteration/readme/DESCRIPTION.rst b/resource_calendar_schedule_iteration/readme/DESCRIPTION.rst index b60db4a25..46c4754a0 100644 --- a/resource_calendar_schedule_iteration/readme/DESCRIPTION.rst +++ b/resource_calendar_schedule_iteration/readme/DESCRIPTION.rst @@ -1,13 +1,10 @@ -When you want to plan a number of days in the past or in the future consiering +When you want to plan a number of days in the past or in the future considering a working calendar, Odoo limits the number of days/hours that you can plan ahead. In case that you want to plan days forward/backward, it currently restricts to 100 iterations. -In case that you want to plan hours forward/backward, it currently restricts -to 100 iterations. - This module allows you to increase the iteration limit used in the resource calendar to schedule days or hours by means of a system parameter defined by the administrator. diff --git a/resource_calendar_schedule_iteration/static/description/index.html b/resource_calendar_schedule_iteration/static/description/index.html index ad0d5a040..99c5db03a 100644 --- a/resource_calendar_schedule_iteration/static/description/index.html +++ b/resource_calendar_schedule_iteration/static/description/index.html @@ -3,13 +3,13 @@ - -Resource Calendar Schedule Iterations + +Resource Calendar Schedule Iteration -
-

Resource Calendar Schedule Iterations

+
+

Resource Calendar Schedule Iteration

-

Beta License: LGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

-

When you want to plan a number of days in the past or in the future consiering +

Beta License: LGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

+

When you want to plan a number of days in the past or in the future considering a working calendar, Odoo limits the number of days/hours that you can plan ahead.

In case that you want to plan days forward/backward, it currently restricts to 100 iterations.

-

In case that you want to plan hours forward/backward, it currently restricts -to 100 iterations.

This module allows you to increase the iteration limit used in the resource calendar to schedule days or hours by means of a system parameter defined by the administrator.

@@ -372,7 +392,7 @@ by the administrator.

Configuration

    -
  1. Go to Ŝettings and activate the developer mode.
  2. +
  3. Go to Settings and activate the developer mode.
  4. Go to Settings / Technical / Parameters / System Parameters and define, new values for the parameters resource.calendar.schedule.days.iteration.limit and/or resource.calendar.schedule.hours.iteration.limit
  5. @@ -383,7 +403,7 @@ and/or resource.calendar.schedule.hours.iteration.limit

    Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -feedback.

    +feedback.

    Do not contact contributors directly about support or help with technical issues.

@@ -397,8 +417,11 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

Contributors

@@ -408,7 +431,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

-

This module is part of the OCA/server-tools project on GitHub.

+

This module is part of the OCA/server-tools project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/resource_calendar_schedule_iteration/tests/__init__.py b/resource_calendar_schedule_iteration/tests/__init__.py new file mode 100644 index 000000000..b839f4dd5 --- /dev/null +++ b/resource_calendar_schedule_iteration/tests/__init__.py @@ -0,0 +1 @@ +from . import test_resource_calendar_schedule_iteration diff --git a/resource_calendar_schedule_iteration/tests/test_resource_calendar_schedule_iteration.py b/resource_calendar_schedule_iteration/tests/test_resource_calendar_schedule_iteration.py new file mode 100644 index 000000000..74566f0eb --- /dev/null +++ b/resource_calendar_schedule_iteration/tests/test_resource_calendar_schedule_iteration.py @@ -0,0 +1,46 @@ +# Copyright 2019 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from datetime import datetime, timedelta + +import odoo.tests.common as common + + +class TestResourceCalendarScheduleIteration(common.TransactionCase): + + def setUp(self): + super(TestResourceCalendarScheduleIteration, self).setUp() + + self.icp = self.env['ir.config_parameter'] + + self.calendar = self.env.ref('resource.resource_calendar_std') + self.icp.set_param( + "resource.calendar.schedule.days.iteration.limit", 200) + + def test_01_days_iteration(self): + days = 150 + calendar_day = self.calendar.plan_days(-1 * days - 1, datetime.today()) + aprox_date = datetime.today() - timedelta(days=days) + # Without more iteration limit the date returned will be only 100 + # days back using calendar (default iteration limit) instead of 150. + self.assertLess(calendar_day, aprox_date) + + def test_02_hours_iteration(self): + hours = 1500 * 8 + hours_2 = 1700 * 8 + limit_hour = self.calendar.plan_hours(-1 * hours - 1, datetime.today()) + limit_hour_2 = self.calendar.plan_hours( + -1 * hours_2 - 1, datetime.today()) + # Both hour computation exceeded the limit so they should be the + # same (which is incorrect). + self.assertEqual(limit_hour, limit_hour_2) + self.icp.set_param( + "resource.calendar.schedule.hours.iteration.limit", 2000) + correct_hour = self.calendar.plan_hours( + -1 * hours - 1, datetime.today()) + correct_hour_2 = self.calendar.plan_hours( + -1 * hours_2 - 1, datetime.today()) + self.assertNotEqual(correct_hour, correct_hour_2) + self.assertLess(correct_hour, limit_hour) + self.assertLess(correct_hour_2, limit_hour_2)