Skip to content

Commit

Permalink
Merge pull request #311 from akretion/16-mig-project_estimate_step
Browse files Browse the repository at this point in the history
16 mig project estimate step
  • Loading branch information
florian-dacosta authored Jul 18, 2024
2 parents accdf50 + 7a2b14e commit 795f403
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 0 deletions.
1 change: 1 addition & 0 deletions project_estimate_step/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
1 change: 1 addition & 0 deletions project_estimate_step/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
29 changes: 29 additions & 0 deletions project_estimate_step/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2022 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Project Estimate Step",
"summary": "Add step estimation for project",
"version": "16.0.1.0.0",
"development_status": "Beta",
"category": "Project",
"website": "https://github.com/akretion/ak-odoo-incubator",
"author": " Akretion",
"license": "AGPL-3",
"external_dependencies": {
"python": [],
"bin": [],
},
"depends": [
"project_time_in_day",
],
"data": [
"views/project_project_view.xml",
"views/project_task_view.xml",
"views/project_task_type_view.xml",
"views/project_estimate_step_view.xml",
"security/ir.model.access.csv",
],
"demo": [],
}
4 changes: 4 additions & 0 deletions project_estimate_step/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import project_project
from . import project_task
from . import project_estimate_step
from . import project_task_type
14 changes: 14 additions & 0 deletions project_estimate_step/models/project_estimate_step.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2022 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ProjectEstimateStep(models.Model):
_name = "project.estimate.step"
_description = "Project Estimate Step"
_order = "days, name"

name = fields.Char(required=True)
days = fields.Float(required=True)
13 changes: 13 additions & 0 deletions project_estimate_step/models/project_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2022 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[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"

estimate_step_ids = fields.Many2many(
comodel_name="project.estimate.step", string="Estimate Step"
)
58 changes: 58 additions & 0 deletions project_estimate_step/models/project_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2022 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models

HOURS_PER_DAYS = 8.0 # TODO Make it configurable


class ProjectTask(models.Model):
_inherit = "project.task"

allowed_estimate_step_ids = fields.Many2many(
comodel_name="project.estimate.step",
related="project_id.estimate_step_ids",
string="Allowed Estimate Step",
)
estimate_step_id = fields.Many2one(
"project.estimate.step",
"Estimate Step",
index=True,
group_expand="_read_group_estimate_step_id",
)

@api.model
def _read_group_estimate_step_id(self, steps, domain, order):
if "default_project_id" in self._context:
project = self.env["project.project"].browse(
self._context["default_project_id"]
)
steps |= project.estimate_step_ids
return steps.sorted("days")

def _sync_estimate(self):
for record in self:
record.planned_hours = record.project_id.convert_days_to_hours(
record.estimate_step_id.days
)

def write(self, vals):
super().write(vals)
if "estimate_step_id" in vals:
self._sync_estimate()
return True

@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
if any(["estimate_step_id" in vals for vals in vals_list]):
records._sync_estimate()
return records

@api.model
def _read_group_stage_ids(self, stages, domain, order):
if self._context.get("no_empty_stage"):
return stages
else:
return super()._read_group_stage_ids(stages, domain, order)
12 changes: 12 additions & 0 deletions project_estimate_step/models/project_task_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2022 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ProjectTaskType(models.Model):
_inherit = "project.task.type"

to_estimate = fields.Boolean()
current_sprint = fields.Boolean()
3 changes: 3 additions & 0 deletions project_estimate_step/security/ir.model.access.csv
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_project_project,project.estimate.step,model_project_estimate_step,project.group_project_user,1,0,0,0
access_project_project_manager,project.estimate.step,model_project_estimate_step,project.group_project_manager,1,1,1,1
53 changes: 53 additions & 0 deletions project_estimate_step/views/project_estimate_step_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="project_estimate_step_view_tree" model="ir.ui.view">
<field name="model">project.estimate.step</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="days" />
</tree>
</field>
</record>

<record id="project_estimate_step_view_form" model="ir.ui.view">
<field name="model">project.estimate.step</field>
<field name="arch" type="xml">
<form string="Estimate Step">
<group>
<field name="name" />
<field name="days" />
</group>
</form>
</field>
</record>

<record id="project_estimate_step_view_search" model="ir.ui.view">
<field name="model">project.estimate.step</field>
<field name="arch" type="xml">
<search string="Estimate Step">
<field name="name" />
<field name="days" />
</search>
</field>
</record>

<record model="ir.actions.act_window" id="project_estimate_step_action">
<field name="name">Estimate Step</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">project.estimate.step</field>
<field name="view_mode">tree,form</field>
<field name="search_view_id" ref="project_estimate_step_view_search" />
<field name="domain">[]</field>
<field name="context">{}</field>
</record>

<menuitem
id="project_estimate_step_menu"
parent="project.menu_project_config"
sequence="20"
action="project_estimate_step_action"
/>

</odoo>
14 changes: 14 additions & 0 deletions project_estimate_step/views/project_project_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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.edit_project" />
<field name="arch" type="xml">
<xpath expr="//group[@name='extra_settings']" position="inside">
<field name="estimate_step_ids" widget="many2many_tags" />
</xpath>
</field>
</record>

</odoo>
15 changes: 15 additions & 0 deletions project_estimate_step/views/project_task_type_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="task_type_edit" model="ir.ui.view">
<field name="model">project.task.type</field>
<field name="inherit_id" ref="project.task_type_edit" />
<field name="arch" type="xml">
<field name="fold" position="after">
<field name="to_estimate" />
<field name="current_sprint" />
</field>
</field>
</record>

</odoo>
41 changes: 41 additions & 0 deletions project_estimate_step/views/project_task_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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.view_task_form2" />
<field name="arch" type="xml">
<field name="tag_ids" position="after">
<field name="allowed_estimate_step_ids" invisible="True" />
<field
name="estimate_step_id"
domain="[('id', 'in', allowed_estimate_step_ids)]"
attrs="{'invisible': [('allowed_estimate_step_ids', '=', False)]}"
widget="radio"
/>
</field>
</field>
</record>

<record id="view_task_search_form" model="ir.ui.view">
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_search_form" />
<field name="arch" type="xml">
<filter name="stage" position="after">
<filter
string="To estimate"
name="to_estimate"
context="{'group_by':'estimate_step_id'}"
domain="[('stage_id.to_estimate', '=', True)]"
/>
<filter
string="Current Sprint"
name="current_sprint"
context="{'group_by':'stage_id', 'no_empty_stage': True}"
domain="[('stage_id.current_sprint', '=', True)]"
/>
</filter>
</field>
</record>

</odoo>
6 changes: 6 additions & 0 deletions setup/project_estimate_step/setup.py
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,
)

0 comments on commit 795f403

Please sign in to comment.