Browse Source

[11.0] resourece_calendar_schedule_iteration: add tests and some minor corrections

pull/1517/head
Lois Rilo 5 years ago
parent
commit
a74a4bbfe7
  1. 19
      resource_calendar_schedule_iteration/README.rst
  2. 15
      resource_calendar_schedule_iteration/hooks.py
  3. 6
      resource_calendar_schedule_iteration/readme/CONTRIBUTORS.rst
  4. 5
      resource_calendar_schedule_iteration/readme/DESCRIPTION.rst
  5. 55
      resource_calendar_schedule_iteration/static/description/index.html
  6. 1
      resource_calendar_schedule_iteration/tests/__init__.py
  7. 46
      resource_calendar_schedule_iteration/tests/test_resource_calendar_schedule_iteration.py

19
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 :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3 :alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github .. |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 :alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |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 :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/149/11.0 :target: https://runbot.odoo-community.org/runbot/149/11.0
@ -25,16 +25,13 @@ Resource Calendar Schedule Iteration
|badge1| |badge2| |badge3| |badge4| |badge5| |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 a working calendar, Odoo limits the number of days/hours that you can plan
ahead. ahead.
In case that you want to plan days forward/backward, it currently restricts In case that you want to plan days forward/backward, it currently restricts
to 100 iterations. 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 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 calendar to schedule days or hours by means of a system parameter defined
by the administrator. by the administrator.
@ -59,7 +56,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20resource_calendar_schedule_iterations%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20resource_calendar_schedule_iteration%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@ -74,8 +71,10 @@ Authors
Contributors Contributors
~~~~~~~~~~~~ ~~~~~~~~~~~~
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
(https://www.eficent.com)
* Eficent (https://www.eficent.com)
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Lois Rilo Antelo <lois.rilo@eficent.com>
Maintainers 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 mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/11.0/resource_calendar_schedule_iterations>`_ project on GitHub.
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/11.0/resource_calendar_schedule_iteration>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

15
resource_calendar_schedule_iteration/hooks.py

@ -1,22 +1,15 @@
# Copyright 2019 Eficent Business and IT Consulting Services S.L. # Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
import pytz
import datetime import datetime
from datetime import timedelta from datetime import timedelta
from odoo.addons.resource.models.resource import ResourceCalendar 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 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 post_load_hook():
def _new_schedule_days(self, days, day_dt, compute_leaves=False, 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 # HOOK. Use the iterations_limit here
while float_compare(remaining_hours, 0.0, precision_digits=2) in ( while float_compare(remaining_hours, 0.0, precision_digits=2) in (
1, 0) and iterations < 1000:
1, 0) and iterations < iterations_limit:
if backwards: if backwards:
call_args['end_time'] = current_datetime.time() call_args['end_time'] = current_datetime.time()
else: else:
@ -117,10 +110,10 @@ def post_load_hook():
ResourceCalendar._schedule_days_original = \ ResourceCalendar._schedule_days_original = \
ResourceCalendar._schedule_days ResourceCalendar._schedule_days
ResourceCalendar._schedule_days = _new_schedule_days
ResourceCalendar._patch_method("_schedule_days", _new_schedule_days)
if not hasattr(ResourceCalendar, '_schedule_hours_original'): if not hasattr(ResourceCalendar, '_schedule_hours_original'):
ResourceCalendar._schedule_hours_original = \ ResourceCalendar._schedule_hours_original = \
ResourceCalendar._schedule_hours ResourceCalendar._schedule_hours
ResourceCalendar._schedule_hours = _new_schedule_hours
ResourceCalendar._patch_method("_schedule_hours", _new_schedule_hours)

6
resource_calendar_schedule_iteration/readme/CONTRIBUTORS.rst

@ -1,2 +1,4 @@
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
(https://www.eficent.com)
* Eficent (https://www.eficent.com)
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Lois Rilo Antelo <lois.rilo@eficent.com>

5
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 a working calendar, Odoo limits the number of days/hours that you can plan
ahead. ahead.
In case that you want to plan days forward/backward, it currently restricts In case that you want to plan days forward/backward, it currently restricts
to 100 iterations. 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 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 calendar to schedule days or hours by means of a system parameter defined
by the administrator. by the administrator.

55
resource_calendar_schedule_iteration/static/description/index.html

@ -3,13 +3,13 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" />
<title>Resource Calendar Schedule Iterations</title>
<meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" />
<title>Resource Calendar Schedule Iteration</title>
<style type="text/css"> <style type="text/css">
/* /*
:Author: David Goodger (goodger@python.org) :Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7614 2013-02-21 15:55:51Z milde $
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain. :Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils. Default cascading style sheet for the HTML output of Docutils.
@ -37,6 +37,14 @@ table.borderless td, table.borderless th {
.hidden { .hidden {
display: none } display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref { a.toc-backref {
text-decoration: none ; text-decoration: none ;
color: black } color: black }
@ -161,12 +169,12 @@ h2.subtitle {
hr.docutils { hr.docutils {
width: 75% } width: 75% }
img.align-left, .figure.align-left, object.align-left {
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ; clear: left ;
float: left ; float: left ;
margin-right: 1em } margin-right: 1em }
img.align-right, .figure.align-right, object.align-right {
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ; clear: right ;
float: right ; float: right ;
margin-left: 1em } margin-left: 1em }
@ -177,6 +185,11 @@ img.align-center, .figure.align-center, object.align-center {
margin-right: auto; margin-right: auto;
} }
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left { .align-left {
text-align: left } text-align: left }
@ -194,6 +207,15 @@ div.align-right {
/* div.align-center * { */ /* div.align-center * { */
/* text-align: left } */ /* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple { ol.simple, ul.simple {
margin-bottom: 1em } margin-bottom: 1em }
@ -338,21 +360,19 @@ ul.auto-toc {
</style> </style>
</head> </head>
<body> <body>
<div class="document" id="resource-calendar-schedule-iterations">
<h1 class="title">Resource Calendar Schedule Iterations</h1>
<div class="document" id="resource-calendar-schedule-iteration">
<h1 class="title">Resource Calendar Schedule Iteration</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-tools/tree/11.0/resource_calendar_schedule_iterations"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-tools-11-0/server-tools-11-0-resource_calendar_schedule_iterations"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/149/11.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>When you want to plan a number of days in the past or in the future consiering
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-tools/tree/11.0/resource_calendar_schedule_iteration"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-tools-11-0/server-tools-11-0-resource_calendar_schedule_iteration"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/149/11.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>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 a working calendar, Odoo limits the number of days/hours that you can plan
ahead.</p> ahead.</p>
<p>In case that you want to plan days forward/backward, it currently restricts <p>In case that you want to plan days forward/backward, it currently restricts
to 100 iterations.</p> to 100 iterations.</p>
<p>In case that you want to plan hours forward/backward, it currently restricts
to 100 iterations.</p>
<p>This module allows you to increase the iteration limit used in the resource <p>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 calendar to schedule days or hours by means of a system parameter defined
by the administrator.</p> by the administrator.</p>
@ -372,7 +392,7 @@ by the administrator.</p>
<div class="section" id="configuration"> <div class="section" id="configuration">
<h1><a class="toc-backref" href="#id1">Configuration</a></h1> <h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<ol class="arabic simple"> <ol class="arabic simple">
<li>Go to <em>Ŝettings</em> and activate the developer mode.</li>
<li>Go to <em>Settings</em> and activate the developer mode.</li>
<li>Go to <em>Settings / Technical / Parameters / System Parameters</em> and define, <li>Go to <em>Settings / Technical / Parameters / System Parameters</em> and define,
new values for the parameters <em>resource.calendar.schedule.days.iteration.limit</em> new values for the parameters <em>resource.calendar.schedule.days.iteration.limit</em>
and/or <em>resource.calendar.schedule.hours.iteration.limit</em></li> and/or <em>resource.calendar.schedule.hours.iteration.limit</em></li>
@ -383,7 +403,7 @@ and/or <em>resource.calendar.schedule.hours.iteration.limit</em></li>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20resource_calendar_schedule_iterations%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20resource_calendar_schedule_iteration%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -397,8 +417,11 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<div class="section" id="contributors"> <div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2> <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple"> <ul class="simple">
<li>Jordi Ballester Alomar &lt;<a class="reference external" href="mailto:jordi.ballester&#64;eficent.com">jordi.ballester&#64;eficent.com</a>&gt;
(<a class="reference external" href="https://www.eficent.com">https://www.eficent.com</a>)</li>
<li>Eficent (<a class="reference external" href="https://www.eficent.com">https://www.eficent.com</a>)<ul>
<li>Jordi Ballester Alomar &lt;<a class="reference external" href="mailto:jordi.ballester&#64;eficent.com">jordi.ballester&#64;eficent.com</a>&gt;</li>
<li>Lois Rilo Antelo &lt;<a class="reference external" href="mailto:lois.rilo&#64;eficent.com">lois.rilo&#64;eficent.com</a>&gt;</li>
</ul>
</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
@ -408,7 +431,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/11.0/resource_calendar_schedule_iterations">OCA/server-tools</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/11.0/resource_calendar_schedule_iteration">OCA/server-tools</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

1
resource_calendar_schedule_iteration/tests/__init__.py

@ -0,0 +1 @@
from . import test_resource_calendar_schedule_iteration

46
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)
Loading…
Cancel
Save