Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project_task_scheduling: Module for automatic task planning #419

Closed
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5578e2d
project_task_scheduling: New module for automated task scheduling
ernestotejeda Aug 3, 2018
4e5a21e
project_task_scheduling: Fix flake8 errors and fix unit test error
ernestotejeda Sep 19, 2018
07022bb
project_task_scheduling: Fix E231 flake8 error
ernestotejeda Sep 19, 2018
e83e1ce
project_task_scheduling: Use date_start and date_end for scheduling
ernestotejeda Sep 19, 2018
ba1d9f5
project_task_assignment: Update readme description
ernestotejeda Sep 20, 2018
fb3b5c7
project_task_assignment: Change module name to project_task_employee
ernestotejeda Sep 20, 2018
37ac1a5
project_task_schedule: Update dependence on project_task_employee
ernestotejeda Sep 21, 2018
02144ea
project_task_employee: Add domain to employee_id field
ernestotejeda Sep 20, 2018
560de9d
project_task_employee: Refactoring code
ernestotejeda Sep 20, 2018
e62beea
project_task_scheduling: Refactoring code
ernestotejeda Sep 22, 2018
27851be
project_task_scheduling: Improve scheduling for tasks with skill
ernestotejeda Sep 23, 2018
7841cb2
project_task_employee: Add help to fields
ernestotejeda Sep 23, 2018
129ed4e
project_task_scheduling: Add help to fields
ernestotejeda Sep 23, 2018
79045c2
project_task_scheduling: Add references to the readme
ernestotejeda Sep 23, 2018
7e637c3
project_task_scheduling: Improve USAGE section of the readme
ernestotejeda Sep 23, 2018
ab28bee
project_task_employee: Fix unite test error
ernestotejeda Sep 24, 2018
36bc972
project_task_employee: Refactoring code
ernestotejeda Sep 24, 2018
0ceb2d4
project_task_schedule: Fix the way to remove an interval from gaps
ernestotejeda Sep 25, 2018
7920b43
project_task_employee: Add unit test
ernestotejeda Sep 25, 2018
f7211b2
project_task_employee: Set task closed field store=True
ernestotejeda Sep 25, 2018
4101b4c
project_task_scheduling: Add states to proposals.
ernestotejeda Sep 25, 2018
445a350
project_task_scheduling: Change the name of a function
ernestotejeda Sep 25, 2018
05acf10
project_task_scheduling: Refactoring code
ernestotejeda Sep 25, 2018
2f74b5a
project_task_scheduling: Add copyright to files
ernestotejeda Sep 25, 2018
02b6f64
project_task_scheduling: Remove copyright line from __init__.py files
ernestotejeda Sep 26, 2018
de17f06
project_task_employee: Add copyright to files
ernestotejeda Sep 26, 2018
4ea656a
project_task_employee: Refactoring code
ernestotejeda Sep 27, 2018
cd71b48
project_task_scheduling: Refactoring code
ernestotejeda Sep 27, 2018
8b3619c
project_task_scheduling: Improve DESCRIPTION section of the readme
ernestotejeda Sep 27, 2018
608fdbe
project_task_scheduling: Remove the 'closed' field
ernestotejeda Sep 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions project_task_employee/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ class Task(models.Model):
help="Only employee selected on the project belonging to the task "
"that have the categories selected here can do the task.",
)
scheduled = fields.Boolean(
compute='_compute_scheduled',
readonly=True,
store=True,
)

@api.multi
@api.depends('project_id.employee_ids.category_ids',
Expand All @@ -47,21 +42,14 @@ def _compute_employee_domain_ids(self):
record.employee_domain_ids = emp.ids

@api.multi
@api.depends('project_id.employee_ids.category_ids',
'employee_category_id')
@api.depends('date_end', 'employee_id', 'employee_domain_ids')
def _compute_employee_scheduling_ids(self):
for record in self:
employees = record.employee_id
if record.date_end or not record.employee_id:
employees = record.employee_domain_ids
record.employee_scheduling_ids = employees

@api.multi
@api.depends('employee_id', 'date_start', 'date_end')
def _compute_scheduled(self):
for record in self:
record.scheduled = record.date_end

@api.onchange('employee_domain_ids')
def _onchange_employee_domain_ids(self):
if self.employee_id not in self.employee_domain_ids:
Expand Down
20 changes: 20 additions & 0 deletions project_task_employee/tests/test_project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@ def test_employee_domain_ids(self):
self.assertEqual(self.task_2.employee_domain_ids, jth + root)
self.assertEqual(self.task_7.employee_domain_ids, root)
self.assertEqual(self.task_1.employee_domain_ids, jth)

def test_change_employee_domain_ids_and_employee_id(self):
with self.env.do_in_onchange():

self.task_3.user_id = False
self.assertFalse(self.task_3.user_id)

self.task_3.employee_id = self.env.ref("hr.employee_root")
self.task_3._onchange_employee_id()
user = self.env.ref("base.user_root")
self.assertEqual(self.task_3.user_id, user)

category_5 = self.env.ref("hr.employee_category_5")
self.task_3.employee_category_id = category_5
self.task_3._onchange_employee_domain_ids()
self.assertFalse(self.task_3.employee_id)

self.assertEqual(self.task_3.user_id, user)
self.task_3._onchange_employee_id()
self.assertFalse(self.task_3.user_id)
1 change: 1 addition & 0 deletions project_task_scheduling/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2018 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models
from . import wizards
1 change: 1 addition & 0 deletions project_task_scheduling/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2018 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Automating Project Task Scheduling",
Expand Down
1 change: 1 addition & 0 deletions project_task_scheduling/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2018 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import project
from . import project_task_scheduling
Expand Down
2 changes: 2 additions & 0 deletions project_task_scheduling/models/project.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2018 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models

Expand All @@ -7,4 +8,5 @@ class Task(models.Model):

closed = fields.Boolean(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this field be moved to module project_stage_closed ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you all right, i have made a Pull Request to add closed field in project_stage_closed. When that PR is merged, then I remove the field of here.
PR: #434

related='stage_id.closed',
store=True,
)
5 changes: 3 additions & 2 deletions project_task_scheduling/models/project_task_scheduling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
# Copyright 2018 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


Expand Down Expand Up @@ -44,7 +45,7 @@ def _compute_delayed(self):
rec.delayed = date_deadline < datetime_stop.date()

@api.multi
def action_set_assignation(self):
def set_assignation(self):
for record in self:
record.task_id.write({
'employee_id': record.employee_id.id,
Expand Down
28 changes: 25 additions & 3 deletions project_task_scheduling/models/project_task_scheduling_proposal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2018 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from datetime import datetime, time
from odoo import api, fields, models, _
Expand All @@ -18,7 +19,7 @@ class ProjectTaskScheduling(models.TransientModel):
duration = fields.Float(
compute='_compute_end'
)
delayed_tasks = fields.Float(
delayed_tasks = fields.Integer(
compute='_compute_delayed_tasks'
)
evaluation = fields.Float(
Expand All @@ -35,6 +36,14 @@ class ProjectTaskScheduling(models.TransientModel):
string="Not scheduled tasks",
readonly=True,
)
state = fields.Selection(
selection=[
('proposed', 'Proposed'),
('approved', 'Approved'),
('rejected', 'Rejected'),
],
default='proposed',
)

@api.multi
@api.depends('task_scheduling_ids.datetime_stop', 'date_start')
Expand Down Expand Up @@ -73,9 +82,15 @@ def action_timeline_scheduling(self):
}

@api.multi
def action_set_scheduling(self):
def action_approve(self):
self.ensure_one()
self.task_scheduling_ids.action_set_assignation()
self.task_scheduling_ids.set_assignation()
self.search([('id', '!=', self.id)]).action_reject()
self.state = 'approved'

@api.multi
def action_reject(self):
self.write({'state': 'rejected'})

@api.multi
def action_recompute(self):
Expand All @@ -102,3 +117,10 @@ def action_recompute(self):
hours_dy += max_hours_delayed
evaluation = task_dy_count * max_hours_delayed * 2 + hours_dy
self.evaluation = round(evaluation, 10)

@api.multi
def copy(self, default=None):
if self.search([('state', '=', 'approved')]):
raise ValidationError(_("You can't duplicate a proposal if there "
"is a proposal approved "))
return super(ProjectTaskScheduling, self).copy(default=default)
2 changes: 1 addition & 1 deletion project_task_scheduling/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ To use this module, you need to:
#. Go to Project > Automation > Project task scheduler
#. Choose a task option (Not finished, Not Scheduled, Customized), a Date Start and Calculation Speed (Slow, Middle, Fast)
#. Click on Accept button
#. You will see a list of proposals of scheduling. For each proposal you can see a time line view for all task grouped by employee. You can also click on one item to see all data of the scheduling in a form view and set it as a definitive scheduling.
#. You will see a list of proposals of scheduling. For each proposal you can see a time line view for all task grouped by employee. You can also click on one item to see all data of the scheduling in a form view and approve or reject this proposal.
1 change: 1 addition & 0 deletions project_task_scheduling/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2018 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import common
from . import test_scheduling_wizard
Expand Down
1 change: 1 addition & 0 deletions project_task_scheduling/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2018 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from datetime import date, datetime, time
from odoo.tests.common import TransactionCase
Expand Down
23 changes: 21 additions & 2 deletions project_task_scheduling/tests/test_scheduling_proposal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Copyright 2018 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError

from odoo.addons.project_task_scheduling.tests.common import \
TestSchedulingCommon

Expand Down Expand Up @@ -29,11 +32,13 @@ def test_computed_fields(self):
self.assertEqual(duration, best_proposal.duration)
self.assertEqual(delayed_tasks, best_proposal.delayed_tasks)

def test_action_set_scheduling(self):
def test_action_approve(self):
self.wizard.action_accept()
proposals = self.env['project.task.scheduling.proposal'].search([])
proposals[-1].action_timeline_scheduling()
proposals[-1].action_set_scheduling()
proposals[-1].action_approve()

self.assertTrue(proposals[-1].state == 'approved')

self.assertTrue(self.task_2.employee_id)
self.assertTrue(self.task_2.date_start)
Expand All @@ -50,3 +55,17 @@ def test_action_set_scheduling(self):
self.assertTrue(self.task_1.employee_id)
self.assertTrue(self.task_1.date_start)
self.assertTrue(self.task_1.date_end)

def test_action_reject(self):
self.wizard.action_accept()
proposals = self.env['project.task.scheduling.proposal'].search([])
proposals[-1].action_reject()
self.assertTrue(proposals[-1].state == 'rejected')

def test_copy(self):
self.wizard.action_accept()
proposals = self.env['project.task.scheduling.proposal'].search([])
proposals[-1].copy()
proposals[-1].action_approve()
with self.assertRaises(ValidationError):
proposals[-1].copy()
19 changes: 11 additions & 8 deletions project_task_scheduling/tests/test_scheduling_wizard.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2018 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from collections import namedtuple
from datetime import date, datetime, time, timedelta
Expand Down Expand Up @@ -140,12 +141,12 @@ def test_get_init_state(self):
self.assertEqual(assigment.end_datetime, data_check[1])
self.assertEqual(assigment.data['employee'], data_check[2])

def test_obj_func(self):
def test_evaluation_function(self):
max_hours_delayed = self.wizard._MAX_HOURS_DELAYED

# evaluate initial state
init_state = self.wizard._get_init_state()
evaluation = self.wizard._obj_func(init_state)
evaluation = self.wizard._evaluation_function(init_state)

# two tasks are scheduled after their date_deadline
# (self.task_7 and self.task_1) see test_get_init_state_1 method
Expand All @@ -165,14 +166,14 @@ def test_obj_func(self):

self.assertEqual(evaluation, expected_eval)

def test_obj_func_fail(self):
def test_evaluation_function_fail(self):
date_start = fields.Datetime.from_string(self.wizard.date_start)
date_deadline = date_start + timedelta(days=50000)
self.task_2.write({'date_deadline': date_deadline})

state = self.wizard._get_init_state()
with self.assertRaises(ValidationError):
self.wizard._obj_func(state)
self.wizard._evaluation_function(state)

def test_generate_neighbor_false(self):
init_st = self.wizard._get_init_state()
Expand Down Expand Up @@ -218,20 +219,22 @@ def test_generate_neighbor_pos_arg_1(self):

def test_generate_neighbor_pos_arg_1_is_better_than_start_state(self):
init_st = self.wizard._get_init_state()
eval_init_st = round(self.wizard._obj_func(init_st), 10)
eval_init_st = round(self.wizard._evaluation_function(init_st), 10)

neighbor_st = self.wizard._generate_neighbor(init_st, pos_arg=1)
eval_neighbor_st = round(self.wizard._obj_func(neighbor_st), 10)
eval_neighbor_st = self.wizard._evaluation_function(neighbor_st)
eval_neighbor_st = round(eval_neighbor_st, 10)

self.assertLess(eval_neighbor_st, eval_init_st)

def test_simulated_annealing_can_improve_initial_state(self):
init_state = self.wizard._get_init_state()
eval_init_st = round(self.wizard._obj_func(init_state), 10)
eval_init_st = round(self.wizard._evaluation_function(init_state), 10)

cooling_ratio = float(self.wizard.cooling_ratio)
sa_state = self.wizard.simulated_annealing(cooling_ratio=cooling_ratio)
eval_sa_state = round(self.wizard._obj_func(sa_state[-1]), 10)
eval_sa_state = self.wizard._evaluation_function(sa_state[-1])
eval_sa_state = round(eval_sa_state, 10)

self.assertLessEqual(eval_sa_state, eval_init_st)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).-->
<!-- Copyright 2018 Tecnativa - Ernesto Tejeda
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo>

<menuitem id="project_task_scheduling_menu"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).-->
<!-- Copyright 2018 Tecnativa - Ernesto Tejeda
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo>

<record id="project_task_scheduling_proposal_view_form" model="ir.ui.view">
Expand All @@ -8,57 +9,63 @@
<field name="arch" type="xml">
<form>
<header>
<button name="action_recompute"
<button name="action_approve"
type="object"
string="Re-compute evaluation"
icon="fa-check"/>
string="Approve"
states="proposed"
class="oe_highlight"
confirm="Are you sure you want to approve this proposal?"/>
<button name="action_reject"
type="object"
string="Reject"
states="proposed"
confirm="Are you sure you want to reject this proposal?"/>
<field name="state" widget="statusbar"/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
<button name="action_timeline_scheduling"
type="object"
string="View scheduling"
icon="fa-clock-o"/>
<button name="action_set_scheduling"
<button name="action_recompute"
type="object"
string="Set scheduling"
icon="fa-check"
confirm="Are you sure you want to set this proposal as definitive?"/>
string="Re-compute evaluation"
icon="fa-gears"
attrs="{'invisible': [('state', 'not in', 'proposed')]}"
/>
</div>
<div class="oe_title">
<h1>
<field name="description" placeholder="Short description..."/>
<field name="description"
placeholder="Short description..."
attrs="{'readonly': [('state', 'not in', 'proposed')]}"/>
</h1>
</div>
<group col="4">
<field name="date_start"/>
<field name="date_end"/>
<field name="duration"/>
<field name="delayed_tasks"/>
<field name="evaluation"/>
<field name="date_start" attrs="{'readonly': [('state', 'not in', 'proposed')]}"/>
<field name="date_end" attrs="{'readonly': [('state', 'not in', 'proposed')]}"/>
<field name="duration" attrs="{'readonly': [('state', 'not in', 'proposed')]}"/>
<field name="delayed_tasks" attrs="{'readonly': [('state', 'not in', 'proposed')]}"/>
<field name="evaluation" attrs="{'readonly': [('state', 'not in', 'proposed')]}"/>
</group>
<notebook>
<page string="Scheduling" name="scheduling">
<group>
<field name="task_scheduling_ids" nolabel="1">
<field name="task_scheduling_ids" nolabel="1" attrs="{'readonly': [('state', 'not in', 'proposed')]}">
<tree>
<field name="employee_id"/>
<field name="task_id"/>
<field name="datetime_start"/>
<field name="datetime_stop"/>
<field name="delayed"/>
<button name="action_set_assignation"
type="object"
string="Set assignation"
icon="fa-check"
confirm="Are you sure you want to set this assignation as definitive?"/>
</tree>
</field>
</group>
</page>
<page string="Not scheduled tasks" name="not_scheduled_task">
<group>
<field name="not_scheduled_task_ids" nolabel="1"/>
<field name="not_scheduled_task_ids" nolabel="1" attrs="{'readonly': [('state', 'not in', 'proposed')]}"/>
</group>
</page>
</notebook>
Expand All @@ -71,13 +78,17 @@
<field name="name">project.task.scheduling.proposal.tree</field>
<field name="model">project.task.scheduling.proposal</field>
<field name="arch" type="xml">
<tree>
<tree decoration-success="state == 'approved'"
decoration-bf="state == 'approved'"
decoration-muted="state == 'rejected'"
create="false" >
<field name="description"/>
<field name="date_start"/>
<field name="date_end"/>
<field name="duration"/>
<field name="delayed_tasks"/>
<field name="evaluation"/>
<field name="state"/>
<button name="action_timeline_scheduling" type="object"
string="View scheduling" icon="fa-clock-o"/>
</tree>
Expand Down
Loading