Skip to content

[16.0][ADD] project_task_code_portal: use task code #1444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
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
133 changes: 133 additions & 0 deletions project_task_code_portal/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
========================
Project Task Code Portal
========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:XXXXXXXXXXXXXXXXXXXXXXXX
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/licence-AGPL--3-blue.png
: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/16.0/project_task_code_portal
:alt: OCA/project
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/project-16-0/project-16-0-project_task_code_portal
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/project&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module implements task codes in the portal. It allows users to:

- Use task codes instead of IDs in portal URLs.
- Search for tasks by their unique code.
- Display task codes in portal task views.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

Business Need
-------------

Task codes provide great flexibility for backend users. However portal
users still have to deal with task id's instead of task codes, which can
be misleading and create potential issues.

Approach
--------

This module extends the standard project portal by allowing:

- Searching for tasks by their unique code.
- Displaying the task code in both list and detail views.
- Generating reports that include the task code.

Use Cases
---------

- Clients can directly access a task via a URL containing the task code.
- Support teams can quickly locate a task using its unique identifier.

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

No configuration is required.

Usage
=====

This module will replace the "ID" field with the "Code" in the following
portal views:

- Task list (including the project task list)
- Task page
- Task search

It will modify the portal URLs as follows:

- **Before:** ``https://example.com/my/tasks/<task_id>``
- **After:** ``https://example.com/my/tasks/<task_code>``

Changelog
=========



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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/project/issues/new?body=module:%20project_task_code_portal%0Aversion:%2016.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.

Credits
=======

Authors
-------

* Cetmix OÜ

Contributors
------------

- `Cetmix <https://cetmix.com/>`__:

- Ivan Sokolov
- Anatol Mikheev

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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/16.0/project_task_code_portal>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions project_task_code_portal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import controllers
from . import models
18 changes: 18 additions & 0 deletions project_task_code_portal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2025 Cetmix OÜ
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Project Task Code Portal",
"summary": "Use custom task code in customer portal",
"version": "16.0.1.0.0",
"development_status": "Beta",
"category": "Project",
"website": "https://github.com/OCA/project",
"author": "Cetmix OÜ, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"project_task_code",
],
"data": [
"templates/portal_templates.xml",
],
}
3 changes: 3 additions & 0 deletions project_task_code_portal/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import portal
91 changes: 91 additions & 0 deletions project_task_code_portal/controllers/portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright (C) 2025 Cetmix OÜ
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, http
from odoo.exceptions import AccessError, MissingError
from odoo.http import request

from odoo.addons.project.controllers.portal import ProjectCustomerPortal


class PortalProjectTask(ProjectCustomerPortal):
def _task_get_searchbar_inputs(self, milestones_allowed):
inputs = super()._task_get_searchbar_inputs(milestones_allowed)
if "ref" in inputs and "label" in inputs["ref"]:
inputs["ref"]["label"] = _("Search in Task code")
return inputs

def _task_get_search_domain(self, search_in, search):
domain = super()._task_get_search_domain(search_in, search)
if search_in in ("ref", "all"):
for i, item in enumerate(domain):
if isinstance(item, tuple) and item[0] == "id":
domain[i] = ("code", item[1], item[2])
break
return domain

def get_accessible_task_by_code(self, task_code, access_token):
task_id = (
request.env["project.task"]
.sudo()
.search([("code", "=", task_code)], limit=1)
.id
)
if not task_id:
raise MissingError(_("No task with this code."))
task_sudo = self._document_check_access("project.task", task_id, access_token)
return task_sudo

@http.route(
["/my/tasks/<string:task_code>"], type="http", auth="public", website=True
)
def portal_my_task(
self,
task_code,
report_type=None,
access_token=None,
project_sharing=False,
**kw
):
try:
task_sudo = self.get_accessible_task_by_code(task_code, access_token)
except (AccessError, MissingError):
return request.redirect("/my")

if report_type in ("pdf", "html", "text"):
return self._show_task_report(
task_sudo, report_type, download=kw.get("download")
)

# ensure attachment are accessible with access token inside template
task_sudo.attachment_ids.generate_access_token()
if project_sharing is True:
# Then the user arrives to the stat button shown in form view of project.task
# and the portal user can see only 1 task
# so the history should be reset.
request.session["my_tasks_history"] = task_sudo.ids

Check warning on line 66 in project_task_code_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

project_task_code_portal/controllers/portal.py#L66

Added line #L66 was not covered by tests
values = self._task_get_page_view_values(task_sudo, access_token, **kw)
return request.render("project.portal_my_task", values)

@http.route(
"/my/projects/<int:project_id>/task/<string:task_code>",
type="http",
auth="public",
website=True,
)
def portal_my_project_task(
self, project_id=None, task_code=None, access_token=None, **kw
):
try:
project_sudo = self._document_check_access(
"project.project", project_id, access_token
)
task_sudo = self.get_accessible_task_by_code(task_code, access_token)
except (AccessError, MissingError):
return request.redirect("/my")
task_sudo.attachment_ids.generate_access_token()
values = self._task_get_page_view_values(
task_sudo, access_token, project=project_sudo, **kw
)
values["project"] = project_sudo
return request.render("project.portal_my_task", values)
3 changes: 3 additions & 0 deletions project_task_code_portal/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import project_task
12 changes: 12 additions & 0 deletions project_task_code_portal/models/project_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (C) 2025 Cetmix OÜ
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


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

@property
def SELF_READABLE_FIELDS(self):
return super().SELF_READABLE_FIELDS | {"code"}
1 change: 1 addition & 0 deletions project_task_code_portal/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No configuration is required.
12 changes: 12 additions & 0 deletions project_task_code_portal/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Business Need
Task codes provide great flexibility for backend users. However portal users still have to deal with task id's instead of task codes, which can be misleading and create potential issues.

## Approach
This module extends the standard project portal by allowing:
- Searching for tasks by their unique code.
- Displaying the task code in both list and detail views.
- Generating reports that include the task code.

## Use Cases
- Clients can directly access a task via a URL containing the task code.
- Support teams can quickly locate a task using its unique identifier.
5 changes: 5 additions & 0 deletions project_task_code_portal/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* [Cetmix](https://cetmix.com/):

* Ivan Sokolov
* Anatol Mikheev

5 changes: 5 additions & 0 deletions project_task_code_portal/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module implements task codes in the portal. It allows users to:

- Use task codes instead of IDs in portal URLs.
- Search for tasks by their unique code.
- Display task codes in portal task views.
1 change: 1 addition & 0 deletions project_task_code_portal/readme/HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

11 changes: 11 additions & 0 deletions project_task_code_portal/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This module will replace the "ID" field with the "Code" in the following portal views:

- Task list (including the project task list)
- Task page
- Task search

It will modify the portal URLs as follows:

- **Before:** `https://example.com/my/tasks/<task_id>`
- **After:** `https://example.com/my/tasks/<task_code>`

Empty file.
66 changes: 66 additions & 0 deletions project_task_code_portal/static/description/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Project Task Code Portal</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
line-height: 1.6;
color: #333;
}
h1, h2 {
color: #2c3e50;
}
ul {
margin-left: 20px;
}
code {
background-color: #f4f4f4;
padding: 2px 4px;
border-radius: 3px;
}
</style>
</head>
<body>
<h1>Project Task Code Portal</h1>
<p>
This module implements task codes in the portal by replacing internal task IDs with human-readable codes.
It enhances the customer portal by providing clear task references and improving overall usability.
</p>

<h2>Key Features</h2>
<ul>
<li>Use task codes instead of IDs in portal URLs</li>
<li>Search for tasks by their unique code in portal filters</li>
<li>Display task codes in both task list and detailed views</li>
<li>Maintains backward compatibility with existing ID-based routes</li>
<li>Includes comprehensive documentation for configuration and usage</li>
</ul>

<h2>Usage</h2>
<p>
Once installed and configured, the module modifies portal URLs as follows:
</p>
<ul>
<li><strong>Before:</strong> <code>https://example.com/my/tasks/&lt;task_id&gt;</code></li>
<li><strong>After:</strong> <code>https://example.com/my/tasks/&lt;task_code&gt;</code></li>
</ul>
<p>
Portal users can now easily share and reference tasks using meaningful codes rather than numerical IDs.
</p>

<h2>Installation &amp; Configuration</h2>
<p>
To install the module, copy it into your Odoo <code>addons</code> directory, ensure that all dependencies are met (e.g., <code>project_task_code</code> and <code>portal</code>), and restart the Odoo server.
Detailed configuration instructions are provided in the module documentation.
</p>

<h2>Context</h2>
<p>
This module addresses the need for client-friendly task references in the portal. It was developed to overcome the limitations of using non-intuitive task IDs by introducing unique, human-readable task codes.
This results in improved communication, easier task tracking, and enhanced navigation for end users.
</p>
</body>
</html>
Loading