-
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
eb29080
commit e6f34c1
Showing
12 changed files
with
306 additions
and
1 deletion.
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
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,5 @@ | ||
from . import project_project | ||
from . import project_task_workload | ||
from . import project_task | ||
from . import project_task_workload_addition_type | ||
from . import project_task_workload_addition |
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,14 @@ | ||
# Copyright 2024 Akretion (https://www.akretion.com). | ||
# @author Sébastien BEAU <[email protected]> | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProjectProject(models.Model): | ||
_inherit = "project.project" | ||
|
||
additional_workload_ids = fields.One2many( | ||
"project.task.workload.addition", "project_id", "Additional Workload" | ||
) |
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,84 @@ | ||
# Copyright 2024 Akretion (https://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class ProjectTask(models.Model): | ||
_inherit = "project.task" | ||
|
||
def _get_new_workloads(self): | ||
rv = super()._get_new_workloads() | ||
# super creates a new workload if there are none | ||
# but here we can have only additional workloads | ||
# so we also need to check if the existing workloads are additional | ||
if not rv and all( | ||
workload.additional_workload_id for workload in self.workload_ids | ||
): | ||
rv.append(self._prepare_workload()) | ||
|
||
additional_workloads = { | ||
workload.additional_workload_id: workload | ||
for workload in self.workload_ids | ||
if workload.additional_workload_id | ||
} | ||
# Now we need to create a new workload for each additional workload | ||
for additional_workload in self.project_id.additional_workload_ids: | ||
if additional_workload not in additional_workloads: | ||
rv.append(self._prepare_additional_workload(additional_workload)) | ||
|
||
return rv | ||
|
||
def _get_updated_workloads(self): | ||
# We sort the workloads by additional_workload_id to ensure that the first workload is the main one | ||
self.workload_ids = self.workload_ids.sorted( | ||
key=lambda w: w.additional_workload_id | ||
) | ||
rv = super()._get_updated_workloads() | ||
if rv and rv[0][0].additional_workload_id: | ||
rv = [] | ||
|
||
additional_workloads = { | ||
workload.additional_workload_id: workload | ||
for workload in self.workload_ids | ||
if workload.additional_workload_id | ||
} | ||
# Now we need to update the existing workload for each additional workload | ||
for additional_workload, workload in additional_workloads.items(): | ||
rv.append( | ||
( | ||
workload, | ||
self._prepare_additional_workload(additional_workload), | ||
) | ||
) | ||
|
||
return rv | ||
|
||
def _get_obsolete_workloads(self): | ||
self.workload_ids = self.workload_ids.sorted( | ||
key=lambda w: w.additional_workload_id | ||
) | ||
rv = super()._get_obsolete_workloads() | ||
if rv: | ||
# Do not delete additional workloads | ||
rv = [workload for workload in rv if not workload.additional_workload_id] | ||
|
||
# Remove all additional workloads that are not in the project anymore | ||
additional_workloads = { | ||
workload.additional_workload_id: workload | ||
for workload in self.workload_ids | ||
if workload.additional_workload_id | ||
} | ||
for additional_workload in additional_workloads: | ||
if additional_workload not in self.project_id.additional_workload_ids: | ||
rv.append(additional_workload) | ||
return rv | ||
|
||
def _prepare_additional_workload(self, additional_workload, **extra): | ||
return self._prepare_workload( | ||
additional_workload_id=additional_workload.id, | ||
hours=additional_workload._compute_hours_from_task(self), | ||
user_id=additional_workload.user_id.id, | ||
**extra, | ||
) |
14 changes: 14 additions & 0 deletions
14
project_workload_additions/models/project_task_workload.py
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,14 @@ | ||
# Copyright 2024 Akretion (https://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProjectTaskWorkload(models.Model): | ||
_inherit = "project.task.workload" | ||
|
||
additional_workload_id = fields.Many2one( | ||
"project.task.workload.addition", string="Additional Workload Reference" | ||
) |
43 changes: 43 additions & 0 deletions
43
project_workload_additions/models/project_task_workload_addition.py
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,43 @@ | ||
# Copyright 2024 Akretion (https://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, fields, models | ||
|
||
|
||
class ProjectWorkloadAddition(models.Model): | ||
_name = "project.task.workload.addition" | ||
_description = "Project Task Workload Addition" | ||
|
||
project_id = fields.Many2one("project.project", string="Project", required=True) | ||
type = fields.Many2one( | ||
"project.task.workload.addition.type", string="Addition Type", required=True | ||
) | ||
percentage = fields.Float( | ||
required=True, | ||
string="Added Percentage", | ||
) | ||
user_id = fields.Many2one("res.users", string="User", required=True) | ||
task_id = fields.Many2one("project.task", string="Task", required=True) | ||
|
||
@api.onchange("type") | ||
def _onchange_type(self): | ||
self.percentage = self.type.default_percentage | ||
|
||
def _compute_hours_from_task(self, task): | ||
self.ensure_one() | ||
return task.planned_hours * (self.percentage / 100) | ||
|
||
def name_get(self): | ||
result = [] | ||
for record in self: | ||
result.append( | ||
( | ||
record.id, | ||
_( | ||
"%s additional workload (%d%%)" | ||
% (record.task_id.name, record.percentage) | ||
), | ||
) | ||
) | ||
return result |
16 changes: 16 additions & 0 deletions
16
project_workload_additions/models/project_task_workload_addition_type.py
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,16 @@ | ||
# Copyright 2024 Akretion (https://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProjectWorkloadAdditionType(models.Model): | ||
_name = "project.task.workload.addition.type" | ||
_description = "Project Task Workload Addition Type" | ||
|
||
name = fields.Char(required=True) | ||
description = fields.Text() | ||
default_percentage = fields.Float(required=True, default=10) | ||
active = fields.Boolean(default=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,3 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_edit_project_task_workload_addition,edit project task workload addition,model_project_task_workload_addition,project.group_project_user,1,1,1,1 | ||
access_edit_project_task_workload_addition_type,edit project task workload addition type,model_project_task_workload_addition_type,project.group_project_user,1,1,1,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,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
|
||
<menuitem | ||
id="project_workload_additions_menu" | ||
name="Addition Types" | ||
parent="project_workload.project_workload_menu" | ||
sequence="10" | ||
action="project_task_workload_addition_type_action" | ||
/> | ||
|
||
|
||
</odoo> |
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,33 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
|
||
<record id="edit_project" model="ir.ui.view"> | ||
<field name="model">project.project</field> | ||
<field name="inherit_id" ref="project_workload.edit_project" /> | ||
<field name="arch" type="xml"> | ||
<page name="settings" position="before"> | ||
<page | ||
string="Workload" | ||
groups="project_workload.group_project_workload" | ||
attrs="{'invisible': [('use_workload', '=', False)]}" | ||
> | ||
<group> | ||
<field name="additional_workload_ids"> | ||
<tree editable="bottom"> | ||
<field name="type" /> | ||
<field name="percentage" /> | ||
<field name="user_id" /> | ||
<field | ||
name="task_id" | ||
domain="[('project_id', '=', parent.id)]" | ||
context="{'default_project_id': parent.id}" | ||
/> | ||
</tree> | ||
</field> | ||
</group> | ||
</page> | ||
</page> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
|
||
<record id="view_task_form2" model="ir.ui.view"> | ||
<field name="model">project.task</field> | ||
<field name="inherit_id" ref="project_workload.view_task_form2" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='workload_ids']/tree" position="inside"> | ||
<field name="additional_workload_id" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
60 changes: 60 additions & 0 deletions
60
project_workload_additions/views/project_task_workload_addition_type_views.xml
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,60 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
|
||
<record id="project_task_workload_addition_type_view_tree" model="ir.ui.view"> | ||
<field name="model">project.task.workload.addition.type</field> | ||
<field name="arch" type="xml"> | ||
<tree string="Workload Addition Types"> | ||
<field name="name" /> | ||
<field name="description" /> | ||
<field name="default_percentage" optional="show" /> | ||
</tree> | ||
</field> | ||
</record> | ||
|
||
<record id="project_task_workload_addition_type_view_form" model="ir.ui.view"> | ||
<field name="model">project.task.workload.addition.type</field> | ||
<field name="arch" type="xml"> | ||
<form string="Type"> | ||
<sheet> | ||
<div class="oe_title"> | ||
<h1> | ||
<field name="name" placeholder="Type Name" /> | ||
</h1> | ||
</div> | ||
<group> | ||
<group> | ||
<field name="active" widget="boolean_toggle" /> | ||
<field name="description" /> | ||
<field name="default_percentage" /> | ||
</group> | ||
</group> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="project_task_workload_addition_type_view_search" model="ir.ui.view"> | ||
<field name="model">project.task.workload.addition.type</field> | ||
<field name="arch" type="xml"> | ||
<search string="Workload Addition Types"> | ||
<field name="name" /> | ||
<field name="description" /> | ||
</search> | ||
</field> | ||
</record> | ||
|
||
<record model="ir.actions.act_window" id="project_task_workload_addition_type_action"> | ||
<field name="name">Workload Addition Types</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">project.task.workload.addition.type</field> | ||
<field name="view_mode">tree,form</field> | ||
<field | ||
name="search_view_id" | ||
ref="project_task_workload_addition_type_view_search" | ||
/> | ||
<field name="domain">[]</field> | ||
<field name="context">{}</field> | ||
</record> | ||
|
||
</odoo> |