-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fd9f2b
commit ad310c4
Showing
8 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2024 Akretion (https://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Project Workload Milestone", | ||
"summary": "Add Milestone Support to Project Workload", | ||
"version": "14.0.1.0.0", | ||
"development_status": "Alpha", | ||
"category": "Uncategorized", | ||
"website": "https://github.com/akretion/ak-odoo-incubator", | ||
"author": " Akretion", | ||
"license": "AGPL-3", | ||
"depends": [ | ||
"project_workload", | ||
"project_milestone", | ||
], | ||
"data": [ | ||
"views/project_milestone.xml", | ||
], | ||
"auto_install": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import project_milestone | ||
from . import project_task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from datetime import timedelta | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ProjectMilestone(models.Model): | ||
_inherit = "project.milestone" | ||
|
||
start_date = fields.Date( | ||
string="Start Date", | ||
help="The date when the Milestone should start.", | ||
compute="_compute_milestone_start_date", | ||
store=True, | ||
readonly=False, | ||
) | ||
|
||
@api.constrains("start_date", "target_date") | ||
def _check_start_date(self): | ||
for milestone in self: | ||
if milestone.target_date < milestone.start_date: | ||
raise ValidationError( | ||
_("The end date cannot be earlier than the start date.") | ||
) | ||
|
||
@api.depends("target_date", "project_id") | ||
def _compute_milestone_start_date(self): | ||
for record in self: | ||
if record.start_date: | ||
continue | ||
if not record.target_date: | ||
record.start_date = False | ||
continue | ||
|
||
# Use a simple algorithm to find the start date | ||
# Find previous milestone | ||
previous_milestones = self.search( | ||
[ | ||
("project_id", "=", record.project_id.id), | ||
("target_date", "<", record.target_date), | ||
], | ||
order="target_date desc", | ||
limit=1, | ||
) | ||
# The start date will be the end date of the previous milestone | ||
record.start_date = previous_milestones.target_date + timedelta(days=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, models | ||
|
||
|
||
class ProjectTask(models.Model): | ||
_inherit = "project.task" | ||
|
||
def _prepare_task_dates_vals_from_milestone(self, vals): | ||
# If we create a task with a milestone or affect it after, | ||
# we set the task dates to the milestone dates | ||
|
||
if "milestone_id" in vals: | ||
milestone = self.env["project.milestone"].browse(vals["milestone_id"]) | ||
if milestone: | ||
vals["date_end"] = milestone.target_date | ||
vals["date_start"] = milestone.start_date | ||
return vals | ||
|
||
@api.model | ||
def create(self, vals): | ||
return super().create(self._prepare_task_dates_vals_from_milestone(vals)) | ||
|
||
def write(self, vals): | ||
return super().write(self._prepare_task_dates_vals_from_milestone(vals)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2024 Akretion (http://www.akretion.com). | ||
@author Florian Mounier <[email protected]> | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
|
||
<record id="project_milestone_view_form" model="ir.ui.view"> | ||
<field name="model">project.milestone</field> | ||
<field name="inherit_id" ref="project_milestone.project_milestone_view_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="project_id" position="replace" /> | ||
<field name="target_date" position="before"> | ||
<field name="project_id" /> | ||
</field> | ||
<field name="target_date" position="after"> | ||
<field name="start_date" /> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
1 change: 1 addition & 0 deletions
1
setup/project_workload_milestone/odoo/addons/project_workload_milestone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../project_workload_milestone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |