Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 30 additions & 8 deletions project_task_description_template/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=================================
Project Task Description Template
=================================
Expand All @@ -17,7 +13,7 @@ Project Task Description Template
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github
Expand All @@ -35,17 +31,40 @@ Project Task Description Template
This module allow to define description templates for a task and use
them to generate the description of the task.

Templates can be restricted to some projects, and portal users can use
the templates of their projects when they create tasks from the project
sharing views. A project can also require portal users to select a
template on every new task.

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure this module:

- Go to **Project > Configuration > Task Description Templates** and
create the templates.
- Set **Projects** on a template to restrict it to those projects. A
template without projects is available in all projects for internal
users. Portal users only see the templates linked to their projects.
- In the project settings, enable **Require Description Template on
Portal Tasks** to force portal users to select a template when they
create a task.

Usage
=====

To use this module:

Select the description template you want to use in a task.
Select the description template you want to use in a task. Its content
is added to the task description.

Portal users can also select a template when they create a task from the
project sharing views.

Bug Tracker
===========
Expand All @@ -68,8 +87,11 @@ Authors
Contributors
------------

- Alan Ramos <alan.ramos@jarsa.com>
- ``Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>``\ \_
- Alan Ramos <alan.ramos@jarsa.com>
- ``Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>``\ \_
- `ForgeFlow <https://www.forgeflow.com>`__:

- Thiago Mulero <thiago.mulero@forgeflow.com>

Maintainers
-----------
Expand Down
1 change: 1 addition & 0 deletions project_task_description_template/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"data": [
"security/ir.model.access.csv",
"security/ir_rule_data.xml",
"views/project_project_view.xml",
"views/project_task_view.xml",
"views/project_task_description_template_view.xml",
],
Expand Down
1 change: 1 addition & 0 deletions project_task_description_template/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2023 - Jarsa
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).

from . import project_project
from . import project_task
from . import project_task_description_template
41 changes: 41 additions & 0 deletions project_task_description_template/models/project_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).

from odoo import api, fields, models
from odoo.exceptions import ValidationError


class ProjectProject(models.Model):
_inherit = "project.project"

task_description_template_ids = fields.Many2many(
"project.task.description.template",
"project_task_description_template_project_rel",
"project_id",
"template_id",
string="Task Description Templates",
help="Templates available for the tasks of this project. Templates "
"without projects are also available for internal users.",
)
portal_task_description_template_required = fields.Boolean(
string="Require Description Template on Portal Tasks",
)

@api.constrains(
"privacy_visibility",
"portal_task_description_template_required",
"task_description_template_ids",
)
def _check_portal_task_description_template_required(self):
for project in self:
if (
project.privacy_visibility == "portal"
and project.portal_task_description_template_required
and not project.task_description_template_ids
):
raise ValidationError(
self.env._(
"Project %(project)s requires a description template on "
"portal tasks, so it must have at least one template.",
project=project.display_name,
)
)
68 changes: 67 additions & 1 deletion project_task_description_template/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,80 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).

from odoo import api, fields, models
from odoo.exceptions import ValidationError


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

description_template_id = fields.Many2one(
"project.task.description.template", store=False
"project.task.description.template",
domain="['|', ('project_ids', '=', False), ('project_ids', '=', project_id)]",
)
portal_description_template_required = fields.Boolean(
related="project_id.portal_task_description_template_required"
)
has_description_templates = fields.Boolean(
compute="_compute_has_description_templates"
)

@property
def SELF_READABLE_FIELDS(self):
return super().SELF_READABLE_FIELDS | {
"portal_description_template_required",
"has_description_templates",
}

@property
def SELF_WRITABLE_FIELDS(self):
return super().SELF_WRITABLE_FIELDS | {"description_template_id"}

@api.depends("project_id.task_description_template_ids")
def _compute_has_description_templates(self):
for task in self:
task.has_description_templates = bool(
task.project_id.task_description_template_ids
)

@api.model_create_multi
def create(self, vals_list):
tasks = super().create(vals_list)
if self.env.user._is_portal():
tasks._check_portal_description_template()
return tasks

def write(self, vals):
res = super().write(vals)
if "description_template_id" in vals and self.env.user._is_portal():
self._check_portal_description_template(check_required=False)
return res

def _check_portal_description_template(self, check_required=True):
for task in self:
template = task.description_template_id.sudo()
project = task.project_id.sudo()
if template and project not in template.project_ids:
raise ValidationError(
self.env._(
"The description template %(template)s is not available "
"in project %(project)s.",
template=template.display_name,
project=project.display_name,
)
)
if (
check_required
and not template
and not task.parent_id
and task.portal_description_template_required
):
raise ValidationError(
self.env._(
"A description template is required to create tasks "
"in project %(project)s.",
project=project.display_name,
)
)

@api.onchange("description_template_id")
def _onchange_description_template_id(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,25 @@ class ProjectTaskDescriptionTemplate(models.Model):
description = fields.Html(required=True)
active = fields.Boolean(default=True)
company_id = fields.Many2one("res.company", default=lambda self: self.env.company)
project_ids = fields.Many2many(
"project.project",
"project_task_description_template_project_rel",
"template_id",
"project_id",
string="Projects",
help="Leave empty to make the template available in all projects. "
"Portal users only see the templates linked to their projects.",
)

def write(self, vals):
projects = self.project_ids
res = super().write(vals)
if "project_ids" in vals or "active" in vals:
projects._check_portal_task_description_template_required()
return res

def unlink(self):
projects = self.project_ids
res = super().unlink()
projects._check_portal_task_description_template_required()
return res
10 changes: 10 additions & 0 deletions project_task_description_template/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
To configure this module:

- Go to **Project \> Configuration \> Task Description Templates** and
create the templates.
- Set **Projects** on a template to restrict it to those projects. A
template without projects is available in all projects for internal
users. Portal users only see the templates linked to their projects.
- In the project settings, enable **Require Description Template on
Portal Tasks** to force portal users to select a template when they
create a task.
2 changes: 2 additions & 0 deletions project_task_description_template/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
- Alan Ramos \<<alan.ramos@jarsa.com>\>
- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`_
- [ForgeFlow](https://www.forgeflow.com):
- Thiago Mulero \<<thiago.mulero@forgeflow.com>\>
5 changes: 5 additions & 0 deletions project_task_description_template/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
This module allow to define description templates for a task and use
them to generate the description of the task.

Templates can be restricted to some projects, and portal users can use
the templates of their projects when they create tasks from the project
sharing views. A project can also require portal users to select a
template on every new task.
6 changes: 5 additions & 1 deletion project_task_description_template/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
To use this module:

Select the description template you want to use in a task.
Select the description template you want to use in a task. Its content
is added to the task description.

Portal users can also select a template when they create a task from the
project sharing views.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_model_project_task_description_template,access_model_project_task_description_template,model_project_task_description_template,project.group_project_manager,1,1,1,1
access_model_project_task_description_template_user,access_model_project_task_description_template_user,model_project_task_description_template,project.group_project_user,1,0,0,0
access_model_project_task_description_template_portal,access_model_project_task_description_template_portal,model_project_task_description_template,base.group_portal,1,0,0,0
11 changes: 11 additions & 0 deletions project_task_description_template/security/ir_rule_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@
<field name="perm_create" eval="True" />
<field name="perm_unlink" eval="True" />
</record>
<record id="project_task_description_template_portal_rule" model="ir.rule">
<field name="name">Project Task Description Template: portal users</field>
<field name="model_id" ref="model_project_task_description_template" />
<field name="domain_force">[
('project_ids', 'any', [
('privacy_visibility', '=', 'portal'),
('collaborator_ids.partner_id', 'in', [user.partner_id.id]),
]),
]</field>
<field name="groups" eval="[(4, ref('base.group_portal'))]" />
</record>
</odoo>
Loading
Loading