Skip to content

Commit

Permalink
[MIG] project_recalculate: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernesto Tejeda committed Jan 8, 2022
1 parent 90fabe8 commit 0b97c3a
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 60 deletions.
10 changes: 5 additions & 5 deletions project_recalculate/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Project Recalculate
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github
:target: https://github.com/OCA/project/tree/12.0/project_recalculate
:target: https://github.com/OCA/project/tree/14.0/project_recalculate
:alt: OCA/project
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/project-12-0/project-12-0-project_recalculate
:target: https://translation.odoo-community.org/projects/project-14-0/project-14-0-project_recalculate
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/140/12.0
:target: https://runbot.odoo-community.org/runbot/140/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -93,7 +93,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/project/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/project/issues/new?body=module:%20project_recalculate%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/project/issues/new?body=module:%20project_recalculate%0Aversion:%2014.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.

Expand Down Expand Up @@ -130,6 +130,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/project <https://github.com/OCA/project/tree/12.0/project_recalculate>`_ project on GitHub.
This module is part of the `OCA/project <https://github.com/OCA/project/tree/14.0/project_recalculate>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
7 changes: 4 additions & 3 deletions project_recalculate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@

{
"name": "Project Recalculate",
"version": "12.0.1.0.0",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"version": "14.0.1.0.0",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/project",
"license": "AGPL-3",
"category": "Project",
"depends": [
"hr_timesheet",
],
"data": [
"security/ir.model.access.csv",
"wizard/recalculate_wizard.xml",
"views/project_project_view.xml",
"views/project_task_view.xml",
"views/project_task_stage_view.xml",
"wizard/recalculate_wizard.xml",
],
"installable": True,
}
3 changes: 1 addition & 2 deletions project_recalculate/models/project_project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See README.rst file on addon root folder for license details

from odoo import _, api, fields, models
from odoo import _, fields, models
from odoo.exceptions import UserError


Expand Down Expand Up @@ -41,7 +41,6 @@ def _start_end_dates_prepare(self):
vals["date_start"] = start_task.date_start.date()
return vals

@api.multi
def project_recalculate(self):
"""
Recalculate project tasks start and end dates.
Expand Down
16 changes: 9 additions & 7 deletions project_recalculate/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ class ProjectTask(models.Model):
string="Estimated days",
help="Estimated days to end",
default=1,
oldname="anticipation_days",
)
include_in_recalculate = fields.Boolean(
related="stage_id.include_in_recalculate",
readonly=True,
)
date_start = fields.Datetime(
string="Starting Date",
default=fields.Datetime.now,
index=True,
copy=False,
)

@api.constrains("estimated_days")
def _estimated_days_check(self):
Expand All @@ -38,7 +43,6 @@ def _estimated_days_check(self):
_("Estimated days must be greater than 0.")
)

@api.multi
def _update_recalculated_dates(self, vals):
"""
Try to calculate estimated_days and from_days fields
Expand Down Expand Up @@ -139,7 +143,7 @@ def _resource_calendar_select(self):
company = self.user_id.company_id
else:
# If not assigned user, get company from current user
company = self.env.user.company_id
company = self.env.company
calendar = self.env["resource.calendar"].search(
[("company_id", "=", company.id)], limit=1
)
Expand Down Expand Up @@ -244,7 +248,6 @@ def _calendar_plan_days(self, days, day_date, resource=None, calendar=None):

return planned_dt or False

@api.multi
def task_recalculate(self):
"""Recalculate task start date and end date depending on
project calculation_type, estimated_days and from_days.
Expand Down Expand Up @@ -276,9 +279,9 @@ def task_recalculate(self):
end_planned_dt, resource, calendar
)[1]
if date_start:
date_start = date_start.astimezone(utc)
date_start = date_start.astimezone(utc).replace(tzinfo=None)
if date_end:
date_end = date_end.astimezone(utc)
date_end = date_end.astimezone(utc).replace(tzinfo=None)

task.with_context(task.env.context, task_recalculate=True).write(
{
Expand All @@ -289,7 +292,6 @@ def task_recalculate(self):
)
return True

@api.multi
def write(self, vals):
for this in self:
vals = this._update_recalculated_dates(vals)
Expand Down
11 changes: 6 additions & 5 deletions project_recalculate/models/resource_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime, timedelta
from functools import partial

from odoo import api, models
from odoo import models

from odoo.addons.resource.models.resource import make_aware

Expand All @@ -29,7 +29,6 @@ def get_working_days_of_date(self, start_dt=None, end_dt=None, resource=None):
current += timedelta(days=1)
return days

@api.multi
def plan_days_to_resource(
self, days, day_dt, compute_leaves=False, resource=None, domain=None
):
Expand All @@ -48,7 +47,7 @@ def plan_days_to_resource(
delta = timedelta(days=14)
for n in range(100):
dt = day_dt + delta * n
for start, stop, meta in get_intervals(dt, dt + delta):
for start, stop, meta in get_intervals(dt, dt + delta): # noqa: B007
found.add(start.date())
if len(found) == days:
return revert(stop)
Expand All @@ -60,8 +59,10 @@ def plan_days_to_resource(
delta = timedelta(days=14)
for n in range(100):
dt = day_dt - delta * n
for start, stop, meta in reversed(get_intervals(dt - delta, dt)):
found.add(start.date())
for start, stop, meta in reversed( # noqa: B007
get_intervals(dt - delta, dt)
):
found.add(stop.date())
if len(found) == days:
return revert(start)
return False
Expand Down
2 changes: 2 additions & 0 deletions project_recalculate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_project_recalculate,project.recalculate,model_project_recalculate_wizard,project.group_project_user,1,1,1,1
8 changes: 4 additions & 4 deletions project_recalculate/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<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.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Project Recalculate</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Project Recalculate</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/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/project/tree/12.0/project_recalculate"><img alt="OCA/project" src="https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/project-12-0/project-12-0-project_recalculate"><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/140/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<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/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/project/tree/14.0/project_recalculate"><img alt="OCA/project" src="https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/project-14-0/project-14-0-project_recalculate"><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/140/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module recalculates Task start/end dates depending on Project
start/end dates.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -453,7 +453,7 @@ <h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/project/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/project/issues/new?body=module:%20project_recalculate%0Aversion:%2012.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/project/issues/new?body=module:%20project_recalculate%0Aversion:%2014.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">
Expand Down Expand Up @@ -485,7 +485,7 @@ <h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
<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/project/tree/12.0/project_recalculate">OCA/project</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/project/tree/14.0/project_recalculate">OCA/project</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>
Expand Down
2 changes: 1 addition & 1 deletion project_recalculate/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def setUp(self):
("Monday", "0", 8, 16),
("Tuesday", "1", 8, 16),
("Wednesday", "2", 8, 16),
("Tuesday", "3", 8, 16),
("Thursday", "3", 8, 16),
("Friday", "4", 8, 16),
)
for day in days:
Expand Down
3 changes: 0 additions & 3 deletions project_recalculate/tests/test_project_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def _check_start_end_dates_prepare(self, num_tasks, res):
"name": name,
"date_start": start,
"date": end,
"resource_calendar_id": False,
},
)
# Set days (estimated_days and from_days to tasks)
Expand Down Expand Up @@ -122,7 +121,6 @@ def _project_recalculate(self, num_tasks, res_project, res_tasks):
"name": name,
"date_start": start,
"date": end,
"resource_calendar_id": False,
},
)
# Set days (estimated_days and from_days to tasks)
Expand Down Expand Up @@ -191,7 +189,6 @@ def test_project_recalculate_exceptions(self):
"name": name + "_%d" % num_tasks,
"date_start": start,
"date": end,
"resource_calendar_id": False,
},
)
project.project_recalculate()
Expand Down
3 changes: 0 additions & 3 deletions project_recalculate/tests/test_project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def test_update_recalculated_dates_when_recalculate(self):
"name": "Test project",
"date_start": date(2015, 8, 1),
"date": date(2015, 8, 31),
"resource_calendar_id": False,
},
)
task = project.tasks[0]
Expand Down Expand Up @@ -83,7 +82,6 @@ def test_update_recalculate_dates(self):
"name": name,
"date_start": start,
"date": end,
"resource_calendar_id": False,
},
)

Expand Down Expand Up @@ -134,7 +132,6 @@ def test_estimated_days_check(self):
{
"calculation_type": self.calculation_type,
"name": "test",
"resource_calendar_id": False,
},
)
# ValidationError cases
Expand Down
48 changes: 21 additions & 27 deletions project_recalculate/views/project_project_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,28 @@
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project" />
<field name="arch" type="xml">
<field name="resource_calendar_id" position="after">
<field
name="date_start"
attrs="{'readonly': [('calculation_type', '=', 'date_end')]}"
/>
<field
name="date"
attrs="{'readonly': [('calculation_type', '=', 'date_begin')]}"
/>
<field name="calculation_type" />
<button
name="project_recalculate.wizard_project_recalculate"
type="action"
string="Recalculate project"
icon="fa-cogs"
attrs="{'invisible': [('calculation_type', '=', False)]}"
/>
</field>
<group name="extra_settings" position="before">
<group string="Time Scheduling" name="time_scheduling">
<field name="resource_calendar_id" />
<field
name="date_start"
attrs="{'readonly': [('calculation_type', '=', 'date_end')]}"
/>
<field
name="date"
attrs="{'readonly': [('calculation_type', '=', 'date_begin')]}"
/>
<field name="calculation_type" />
<button
name="%(wizard_project_recalculate)d"
type="action"
string="Recalculate project"
icon="fa-cogs"
attrs="{'invisible': [('calculation_type', '=', False)]}"
/>
</group>
</group>
</field>
</record>

<act_window
name="Project recalculate"
res_model="project.recalculate.wizard"
view_mode="form"
multi="True"
target="new"
id="wizard_project_recalculate"
/>

</odoo>
4 changes: 4 additions & 0 deletions project_recalculate/views/project_task_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<field name="from_days" />
<field name="estimated_days" />
</field>
<field name='date_assign' position="after">
<field name="date_start" />
<field name="date_end" />
</field>
</field>
</record>

Expand Down
7 changes: 7 additions & 0 deletions project_recalculate/wizard/recalculate_wizard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@
</field>
</record>

<record id="wizard_project_recalculate" model="ir.actions.act_window">
<field name="name">Project recalculate</field>
<field name="res_model">project.recalculate.wizard</field>
<field name="binding_view_types">list</field>
<field name="target">new</field>
<field name="view_mode">form</field>
</record>
</odoo>

0 comments on commit 0b97c3a

Please sign in to comment.