Browse Source

Merge pull request #1517 from Eficent/11.0-resource_calendar_schedule_iterations

[11.0][resource_calendar_schedule_iterations]
pull/1388/merge
Pedro M. Baeza 6 years ago
committed by GitHub
parent
commit
c1f91edbec
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 94
      resource_calendar_schedule_iteration/README.rst
  2. 2
      resource_calendar_schedule_iteration/__init__.py
  3. 19
      resource_calendar_schedule_iteration/__manifest__.py
  4. 18
      resource_calendar_schedule_iteration/data/ir_config_parameter_data.xml
  5. 119
      resource_calendar_schedule_iteration/hooks.py
  6. 1
      resource_calendar_schedule_iteration/model/__init__.py
  7. 22
      resource_calendar_schedule_iteration/model/resource_calendar.py
  8. 5
      resource_calendar_schedule_iteration/readme/CONFIGURE.rst
  9. 4
      resource_calendar_schedule_iteration/readme/CONTRIBUTORS.rst
  10. 10
      resource_calendar_schedule_iteration/readme/DESCRIPTION.rst
  11. BIN
      resource_calendar_schedule_iteration/static/description/icon.png
  12. 440
      resource_calendar_schedule_iteration/static/description/index.html
  13. 1
      resource_calendar_schedule_iteration/tests/__init__.py
  14. 46
      resource_calendar_schedule_iteration/tests/test_resource_calendar_schedule_iteration.py

94
resource_calendar_schedule_iteration/README.rst

@ -0,0 +1,94 @@
====================================
Resource Calendar Schedule Iteration
====================================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
: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_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_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
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
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.
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.
**Table of contents**
.. contents::
:local:
Configuration
=============
#. Go to *Settings* and activate the developer mode.
#. 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*
Bug Tracker
===========
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.
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_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.
Credits
=======
Authors
~~~~~~~
* Eficent
Contributors
~~~~~~~~~~~~
* Eficent (https://www.eficent.com)
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Lois Rilo Antelo <lois.rilo@eficent.com>
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
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 <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.

2
resource_calendar_schedule_iteration/__init__.py

@ -0,0 +1,2 @@
from . import model
from .hooks import post_load_hook

19
resource_calendar_schedule_iteration/__manifest__.py

@ -0,0 +1,19 @@
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Resource Calendar Schedule Iteration",
"author": "Eficent, Odoo Community Association (OCA)",
"version": "11.0.1.0.0",
'category': 'Hidden',
"website": "https://github.com/OCA/server-tools",
"depends": [
'resource',
],
"data": [
'data/ir_config_parameter_data.xml',
],
"license": 'LGPL-3',
"post_load": "post_load_hook",
"installable": True
}

18
resource_calendar_schedule_iteration/data/ir_config_parameter_data.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 Eficent Business and IT Consulting Services S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">
<record id="respource_calendar_schedule_days_iteration_limit"
model="ir.config_parameter">
<field name="key">resource.calendar.schedule.days.iteration.limit</field>
<field name="value">100</field>
</record>
<record id="respource_calendar_schedule_hours_iteration_limit"
model="ir.config_parameter">
<field name="key">resource.calendar.schedule.hours.iteration.limit</field>
<field name="value">1000</field>
</record>
</odoo>

119
resource_calendar_schedule_iteration/hooks.py

@ -0,0 +1,119 @@
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
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 post_load_hook():
def _new_schedule_days(self, days, day_dt, compute_leaves=False,
resource_id=None):
if not hasattr(self, '_get_schedule_days_iteration_limit'):
return self._schedule_days_original(
days, day_dt, compute_leaves=compute_leaves,
resource_id=resource_id)
# START OF HOOK: Introduce here the iterations limit
iterations_limit = self._get_schedule_days_iteration_limit() or 100
# END OF HOOK
backwards = (days < 0)
intervals = []
planned_days, iterations = 0, 0
day_dt_tz = to_naive_user_tz(day_dt, self.env.user)
current_datetime = day_dt_tz.replace(
hour=0, minute=0, second=0, microsecond=0)
# HOOK. Use the iterations_limit here
while planned_days < abs(days) and iterations < iterations_limit:
working_intervals = self._get_day_work_intervals(
current_datetime.date(),
compute_leaves=compute_leaves, resource_id=resource_id)
if not self or working_intervals:
# no calendar -> no working hours, but day is
# considered as worked
planned_days += 1
intervals += working_intervals
# get next day
if backwards:
current_datetime = self._get_previous_work_day(
current_datetime)
else:
current_datetime = self._get_next_work_day(current_datetime)
# avoid infinite loops
iterations += 1
return intervals
def _new_schedule_hours(self, hours, day_dt, compute_leaves=False,
resource_id=None):
if not hasattr(self, '_get_schedule_hours_iteration_limit'):
return self._schedule_hours_original(
hours, day_dt, compute_leaves=compute_leaves,
resource_id=resource_id)
self.ensure_one()
# START OF HOOK: Introduce here the iterations limit
iterations_limit = self._get_schedule_hours_iteration_limit() or 1000
# END OF HOOK
backwards = (hours < 0)
intervals = []
remaining_hours, iterations = abs(hours * 1.0), 0
day_dt_tz = to_naive_user_tz(day_dt, self.env.user)
current_datetime = day_dt_tz
call_args = dict(compute_leaves=compute_leaves,
resource_id=resource_id)
# HOOK. Use the iterations_limit here
while float_compare(remaining_hours, 0.0, precision_digits=2) in (
1, 0) and iterations < iterations_limit:
if backwards:
call_args['end_time'] = current_datetime.time()
else:
call_args['start_time'] = current_datetime.time()
working_intervals = self._get_day_work_intervals(
current_datetime.date(), **call_args)
if working_intervals:
new_working_intervals = self._interval_schedule_hours(
working_intervals, remaining_hours, backwards=backwards)
res = timedelta()
for interval in working_intervals:
res += interval[1] - interval[0]
remaining_hours -= res.total_seconds() / 3600.0
intervals = intervals + new_working_intervals if \
not backwards else new_working_intervals + intervals
# get next day
if backwards:
current_datetime = datetime.datetime.combine(
self._get_previous_work_day(current_datetime),
datetime.time(23, 59, 59))
else:
current_datetime = datetime.datetime.combine(
self._get_next_work_day(current_datetime),
datetime.time())
# avoid infinite loops
iterations += 1
return intervals
if not hasattr(ResourceCalendar, '_schedule_days_original'):
ResourceCalendar._schedule_days_original = \
ResourceCalendar._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._patch_method("_schedule_hours", _new_schedule_hours)

1
resource_calendar_schedule_iteration/model/__init__.py

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

22
resource_calendar_schedule_iteration/model/resource_calendar.py

@ -0,0 +1,22 @@
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, models
class ResourceCalendar(models.Model):
_inherit = 'resource.calendar'
@api.multi
def _get_schedule_days_iteration_limit(self):
self.ensure_one()
limit = self.env['ir.config_parameter'].sudo().get_param(
'resource.calendar.schedule.days.iteration.limit', default=False)
return int(limit) or False
@api.multi
def _get_schedule_hours_iteration_limit(self):
self.ensure_one()
limit = self.env['ir.config_parameter'].sudo().get_param(
'resource.calendar.schedule.hours.iteration.limit', default=False)
return int(limit) or False

5
resource_calendar_schedule_iteration/readme/CONFIGURE.rst

@ -0,0 +1,5 @@
#. Go to *Settings* and activate the developer mode.
#. 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*

4
resource_calendar_schedule_iteration/readme/CONTRIBUTORS.rst

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

10
resource_calendar_schedule_iteration/readme/DESCRIPTION.rst

@ -0,0 +1,10 @@
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.
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.

BIN
resource_calendar_schedule_iteration/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

440
resource_calendar_schedule_iteration/static/description/index.html

@ -0,0 +1,440 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" />
<title>Resource Calendar Schedule Iteration</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<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 !!
!! 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_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
ahead.</p>
<p>In case that you want to plan days forward/backward, it currently restricts
to 100 iterations.</p>
<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
by the administrator.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<ol class="arabic simple">
<li>Go to <em>Settings</em> and activate the developer mode.</li>
<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>
and/or <em>resource.calendar.schedule.hours.iteration.limit</em></li>
</ol>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<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.
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_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>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
<ul class="simple">
<li>Eficent</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple">
<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>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</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>
</div>
</div>
</div>
</body>
</html>

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