odoo-addon-project-task-api 16.0.1.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- odoo/addons/project_task_api/CHANGELOG.md +26 -0
- odoo/addons/project_task_api/README.rst +121 -0
- odoo/addons/project_task_api/__init__.py +1 -0
- odoo/addons/project_task_api/__manifest__.py +26 -0
- odoo/addons/project_task_api/data/fastapi_endpoint.xml +10 -0
- odoo/addons/project_task_api/models/__init__.py +3 -0
- odoo/addons/project_task_api/models/fastapi_endpoint.py +40 -0
- odoo/addons/project_task_api/routers/__init__.py +1 -0
- odoo/addons/project_task_api/routers/project_task_router.py +253 -0
- odoo/addons/project_task_api/schemas/__init__.py +2 -0
- odoo/addons/project_task_api/schemas/common.py +6 -0
- odoo/addons/project_task_api/schemas/project_task.py +257 -0
- odoo/addons/project_task_api/static/description/icon.png +0 -0
- odoo/addons/project_task_api/tests/__init__.py +1 -0
- odoo/addons/project_task_api/tests/test_fastapi_endpoint.py +551 -0
- odoo_addon_project_task_api-16.0.1.1.2.dist-info/METADATA +141 -0
- odoo_addon_project_task_api-16.0.1.1.2.dist-info/RECORD +19 -0
- odoo_addon_project_task_api-16.0.1.1.2.dist-info/WHEEL +5 -0
- odoo_addon_project_task_api-16.0.1.1.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
## [16.0.1.1.2] - 2026-12-02
|
|
9
|
+
### Changed
|
|
10
|
+
- [#8](https://git.coopdevs.org/coopdevs/som-connexio/odoo/odoo-custom-modules/-/merge_requests/8) Serve routers of other modules under /project_tasks
|
|
11
|
+
|
|
12
|
+
## [16.0.1.1.1] - 2026-10-21
|
|
13
|
+
### Changed
|
|
14
|
+
- Depend on `project_task_contract` instead of `project_task_somconnexio`.
|
|
15
|
+
|
|
16
|
+
## [16.0.1.1.0] - 2026-10-19
|
|
17
|
+
### Added
|
|
18
|
+
- [#1749](https://git.coopdevs.org/coopdevs/som-connexio/odoo/odoo-somconnexio/-/merge_requests/1749) Allow to add attachments to project.task
|
|
19
|
+
- [#1749](https://git.coopdevs.org/coopdevs/som-connexio/odoo/odoo-somconnexio/-/merge_requests/1749) Link a task to its contract with `contract_code`, on creation and on update
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- [#1749](https://git.coopdevs.org/coopdevs/som-connexio/odoo/odoo-somconnexio/-/merge_requests/1749) `project.project.code` and its form view now come from `project_task_contract`
|
|
23
|
+
|
|
24
|
+
## [16.0.1.0.0] - 2026-09-22
|
|
25
|
+
### Added
|
|
26
|
+
- [#1761](https://git.coopdevs.org/coopdevs/som-connexio/odoo/odoo-somconnexio/-/merge_requests/1761) Add project_task_api
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
##################
|
|
2
|
+
Project Task API
|
|
3
|
+
##################
|
|
4
|
+
|
|
5
|
+
This module uses OCAs FAST API module for creating endpoints to get and
|
|
6
|
+
create project tasks from external applications.
|
|
7
|
+
|
|
8
|
+
.. note::
|
|
9
|
+
|
|
10
|
+
This module is made by and for developers.
|
|
11
|
+
|
|
12
|
+
**Table of contents**
|
|
13
|
+
|
|
14
|
+
.. contents::
|
|
15
|
+
:local:
|
|
16
|
+
|
|
17
|
+
***************
|
|
18
|
+
Configuration
|
|
19
|
+
***************
|
|
20
|
+
|
|
21
|
+
As this module is based on `fastapi_auth_api_key_sc`, an API-KEY is
|
|
22
|
+
required to authenticate requests. Read README from
|
|
23
|
+
`fastapi_auth_api_key_sc` for more information about the user related
|
|
24
|
+
API-KEY authentication.
|
|
25
|
+
|
|
26
|
+
*******
|
|
27
|
+
Usage
|
|
28
|
+
*******
|
|
29
|
+
|
|
30
|
+
This module provides FastAPI-based endpoints of project tasks by
|
|
31
|
+
extending `fastapi.endpoint`.
|
|
32
|
+
|
|
33
|
+
The module registers the following routes:
|
|
34
|
+
|
|
35
|
+
- GET: `/api/project_tasks`
|
|
36
|
+
- POST: `/api/project_tasks`
|
|
37
|
+
- GET: `/api/project_tasks/{id}`
|
|
38
|
+
- PUT: `/api/project_tasks/{id}`
|
|
39
|
+
|
|
40
|
+
The authenticated API uses `API-KEY`
|
|
41
|
+
|
|
42
|
+
Other modules can serve their own routes under `/api/project_tasks`,
|
|
43
|
+
with the same authentication, by extending
|
|
44
|
+
`fastapi.endpoint._get_project_task_routers` to add their router. Their
|
|
45
|
+
routes are relative to `/project_tasks`, so the router does not set the
|
|
46
|
+
prefix itself:
|
|
47
|
+
|
|
48
|
+
.. code:: python
|
|
49
|
+
|
|
50
|
+
new_project_router = APIRouter()
|
|
51
|
+
|
|
52
|
+
@new_project_router.post("/new-project") # POST /api/project_tasks/new-project
|
|
53
|
+
def create_task_new_project(...):
|
|
54
|
+
...
|
|
55
|
+
|
|
56
|
+
class FastapiEndpoint(models.Model):
|
|
57
|
+
_inherit = "fastapi.endpoint"
|
|
58
|
+
|
|
59
|
+
@api.model
|
|
60
|
+
def _get_project_task_routers(self):
|
|
61
|
+
return super()._get_project_task_routers() + [new_project_router]
|
|
62
|
+
|
|
63
|
+
Their tests build the test client with
|
|
64
|
+
`env["fastapi.endpoint"]._get_project_tasks_router()`, so the routes are
|
|
65
|
+
tested at their full path.
|
|
66
|
+
|
|
67
|
+
************************
|
|
68
|
+
Known issues / Roadmap
|
|
69
|
+
************************
|
|
70
|
+
|
|
71
|
+
There are no known issues for this module.
|
|
72
|
+
|
|
73
|
+
*************
|
|
74
|
+
Bug Tracker
|
|
75
|
+
*************
|
|
76
|
+
|
|
77
|
+
Bugs are tracked on `GitLab Issues
|
|
78
|
+
<https://gitlab.com/somitcoop/erp-research/odoo-helpdesk/-/issues>`_. In
|
|
79
|
+
case of trouble, please check there if your issue has already been
|
|
80
|
+
reported. If you spotted it first, help us smashing it by providing a
|
|
81
|
+
detailed and welcomed feedback.
|
|
82
|
+
|
|
83
|
+
Do not contact contributors directly about support or help with
|
|
84
|
+
technical issues.
|
|
85
|
+
|
|
86
|
+
TODO: Module to be substituted by `the OCA module`_ once this ODOO is
|
|
87
|
+
migrated to the 17th version or further.
|
|
88
|
+
|
|
89
|
+
.. _the oca module: https://github.com/OCA/rest-framework/tree/17.0/fastapi_auth_api_key/
|
|
90
|
+
|
|
91
|
+
*********
|
|
92
|
+
Credits
|
|
93
|
+
*********
|
|
94
|
+
|
|
95
|
+
Authors
|
|
96
|
+
=======
|
|
97
|
+
|
|
98
|
+
- Som Connexio SCCL
|
|
99
|
+
|
|
100
|
+
Contributors
|
|
101
|
+
============
|
|
102
|
+
|
|
103
|
+
- `Som Connexio SCCL <https://somconnexio.coop>`_:
|
|
104
|
+
|
|
105
|
+
- Gerard Funosas <gerard.funosas@somconnexio.coop>
|
|
106
|
+
|
|
107
|
+
Maintainers
|
|
108
|
+
===========
|
|
109
|
+
|
|
110
|
+
This module is maintained by the OCA.
|
|
111
|
+
|
|
112
|
+
.. image:: https://odoo-community.org/logo.png
|
|
113
|
+
:alt: Odoo Community Association
|
|
114
|
+
:target: https://odoo-community.org
|
|
115
|
+
|
|
116
|
+
OCA, or the Odoo Community Association, is a nonprofit organization
|
|
117
|
+
whose mission is to support the collaborative development of Odoo
|
|
118
|
+
features and promote its widespread use.
|
|
119
|
+
|
|
120
|
+
You are welcome to contribute. To learn how please visit
|
|
121
|
+
https://odoo-community.org/page/Contribute.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import models, routers, schemas
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
|
2
|
+
{
|
|
3
|
+
"name": "Project Task API",
|
|
4
|
+
"version": "16.0.1.1.2",
|
|
5
|
+
"summary": """
|
|
6
|
+
API module based on FastAPI to get and create project tasks from
|
|
7
|
+
external applications
|
|
8
|
+
""",
|
|
9
|
+
"depends": ["fastapi_auth_api_key_sc", "project", "project_task_contract"],
|
|
10
|
+
"author": """
|
|
11
|
+
Som Connexió SCCL,
|
|
12
|
+
Odoo Community Association (OCA)
|
|
13
|
+
""",
|
|
14
|
+
"category": "API",
|
|
15
|
+
"website": (
|
|
16
|
+
"https://git.coopdevs.org/coopdevs/som-connexio/odoo/odoo-custom-modules"
|
|
17
|
+
),
|
|
18
|
+
"license": "AGPL-3",
|
|
19
|
+
"data": [
|
|
20
|
+
"data/fastapi_endpoint.xml",
|
|
21
|
+
],
|
|
22
|
+
"demo": [],
|
|
23
|
+
"external_dependencies": {"python": ["pydantic", "fastapi"]},
|
|
24
|
+
"application": False,
|
|
25
|
+
"installable": True,
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<odoo>
|
|
3
|
+
<record id="fastapi_project_task_endpoint" model="fastapi.endpoint">
|
|
4
|
+
<field name="name">FastAPi Project Task Endpoint</field>
|
|
5
|
+
<field name="description">Project task endpoint</field>
|
|
6
|
+
<field name="app">fastapi_project_task</field>
|
|
7
|
+
<field name="root_path">/api</field>
|
|
8
|
+
<field name="user_id" ref="fastapi_auth_api_key_sc.fastapi_service_user"/>
|
|
9
|
+
</record>
|
|
10
|
+
</odoo>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from fastapi import APIRouter
|
|
2
|
+
|
|
3
|
+
from odoo import api, fields, models
|
|
4
|
+
|
|
5
|
+
from ..routers.project_task_router import project_task_router
|
|
6
|
+
|
|
7
|
+
PROJECT_TASKS_PREFIX = "/project_tasks"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class FastapiEndpoint(models.Model):
|
|
11
|
+
_inherit = "fastapi.endpoint"
|
|
12
|
+
|
|
13
|
+
app = fields.Selection(
|
|
14
|
+
selection_add=[("fastapi_project_task", "FastAPi Project Task")],
|
|
15
|
+
ondelete={"fastapi_project_task": "cascade"},
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def _get_fastapi_routers(self):
|
|
19
|
+
if self.app == "fastapi_project_task":
|
|
20
|
+
return [self._get_project_tasks_router()]
|
|
21
|
+
return super()._get_fastapi_routers()
|
|
22
|
+
|
|
23
|
+
@api.model
|
|
24
|
+
def _get_project_task_routers(self):
|
|
25
|
+
"""
|
|
26
|
+
Routers served under `/project_tasks`. Modules adding routes under
|
|
27
|
+
it extend this method, so their routers do not repeat the prefix.
|
|
28
|
+
"""
|
|
29
|
+
return [project_task_router]
|
|
30
|
+
|
|
31
|
+
@api.model
|
|
32
|
+
def _get_project_tasks_router(self):
|
|
33
|
+
"""
|
|
34
|
+
Router serving every router of `_get_project_task_routers` under
|
|
35
|
+
`/project_tasks`.
|
|
36
|
+
"""
|
|
37
|
+
router = APIRouter()
|
|
38
|
+
for project_task_subrouter in self._get_project_task_routers():
|
|
39
|
+
router.include_router(project_task_subrouter, prefix=PROJECT_TASKS_PREFIX)
|
|
40
|
+
return router
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import project_task_router
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
from typing import Annotated, List
|
|
2
|
+
from fastapi import APIRouter, Depends, HTTPException, status
|
|
3
|
+
|
|
4
|
+
from odoo.addons.base.models.res_partner import Partner
|
|
5
|
+
from odoo.api import Environment
|
|
6
|
+
from odoo.addons.fastapi.dependencies import odoo_env
|
|
7
|
+
|
|
8
|
+
from odoo.addons.fastapi_auth_api_key_sc.dependencies import (
|
|
9
|
+
authenticated_partner_by_api_key,
|
|
10
|
+
serialize_record,
|
|
11
|
+
)
|
|
12
|
+
from ..schemas.project_task import (
|
|
13
|
+
ProjectTaskCreatePayload,
|
|
14
|
+
ProjectTaskPresenter,
|
|
15
|
+
ProjectTaskUpdatePayload,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
project_task_router = APIRouter()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_partner_by_ref(env, ref):
|
|
22
|
+
partner = (
|
|
23
|
+
env["res.partner"]
|
|
24
|
+
.sudo()
|
|
25
|
+
.search(
|
|
26
|
+
[
|
|
27
|
+
("parent_id", "=", False),
|
|
28
|
+
("ref", "=", ref),
|
|
29
|
+
],
|
|
30
|
+
limit=1,
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
if not partner.exists():
|
|
34
|
+
raise HTTPException(
|
|
35
|
+
status_code=status.HTTP_404_NOT_FOUND,
|
|
36
|
+
detail="Partner with ref {} not found".format(ref),
|
|
37
|
+
)
|
|
38
|
+
return partner
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def get_contract_by_code(env, code, partner=None):
|
|
42
|
+
"""
|
|
43
|
+
Return the contract a task is about.
|
|
44
|
+
|
|
45
|
+
When a partner is given, the contract has to be one of theirs: a
|
|
46
|
+
payload that names both a member and a contract of somebody else
|
|
47
|
+
disagrees with itself about who the task is for, and none of the two
|
|
48
|
+
contracts it points at is the one to write.
|
|
49
|
+
"""
|
|
50
|
+
contract = env["contract.contract"].sudo().search([("code", "=", code)], limit=1)
|
|
51
|
+
if not contract or (partner and contract.partner_id != partner):
|
|
52
|
+
raise HTTPException(
|
|
53
|
+
status_code=status.HTTP_404_NOT_FOUND,
|
|
54
|
+
detail="Contract with code {} not found".format(code),
|
|
55
|
+
)
|
|
56
|
+
return contract
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def get_partner_and_contract_params(env, params):
|
|
60
|
+
"""
|
|
61
|
+
Take `partner_ref` and `contract_code` out of the given payload and
|
|
62
|
+
return the values a task is written with, the same way on creation
|
|
63
|
+
and on update.
|
|
64
|
+
|
|
65
|
+
The contract is the source of truth about who the task is for: the
|
|
66
|
+
member it belongs to owns the task unless the caller names another
|
|
67
|
+
one, and then the two have to agree. A payload that names neither
|
|
68
|
+
leaves the partner of the task to Odoo.
|
|
69
|
+
"""
|
|
70
|
+
partner_ref = params.pop("partner_ref", None)
|
|
71
|
+
contract_code = params.pop("contract_code", None)
|
|
72
|
+
partner = get_partner_by_ref(env, partner_ref) if partner_ref else None
|
|
73
|
+
|
|
74
|
+
values = {}
|
|
75
|
+
if contract_code:
|
|
76
|
+
contract = get_contract_by_code(env, contract_code, partner)
|
|
77
|
+
partner = contract.partner_id
|
|
78
|
+
values["contract_id"] = contract.id
|
|
79
|
+
if partner:
|
|
80
|
+
values["partner_id"] = partner.id
|
|
81
|
+
return values
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def get_project_by_code(env, code):
|
|
85
|
+
project = env["project.project"].sudo().search([("code", "=", code)])
|
|
86
|
+
if not project:
|
|
87
|
+
raise HTTPException(
|
|
88
|
+
status_code=status.HTTP_404_NOT_FOUND,
|
|
89
|
+
detail="Project record with code {} not found".format(code),
|
|
90
|
+
)
|
|
91
|
+
return project
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def attach_documents(env, task_id, documents):
|
|
95
|
+
"""
|
|
96
|
+
Attach the files sent along with a task to it, as they came.
|
|
97
|
+
"""
|
|
98
|
+
if not documents:
|
|
99
|
+
return
|
|
100
|
+
env["ir.attachment"].sudo().create(
|
|
101
|
+
[
|
|
102
|
+
{
|
|
103
|
+
"name": document.name,
|
|
104
|
+
"type": "binary",
|
|
105
|
+
"datas": document.content,
|
|
106
|
+
"res_model": "project.task",
|
|
107
|
+
"res_id": task_id,
|
|
108
|
+
}
|
|
109
|
+
for document in documents
|
|
110
|
+
]
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@project_task_router.get("", response_model=List[ProjectTaskPresenter])
|
|
115
|
+
def list_project_tasks(
|
|
116
|
+
partner: Annotated[Partner, Depends(authenticated_partner_by_api_key)],
|
|
117
|
+
env: Annotated[Environment, Depends(odoo_env)],
|
|
118
|
+
partner_ref: str | None = None,
|
|
119
|
+
project_id: int | None = None,
|
|
120
|
+
partner_phone: str | None = None,
|
|
121
|
+
) -> ProjectTaskPresenter:
|
|
122
|
+
if not partner_ref and not project_id and not partner_phone:
|
|
123
|
+
raise HTTPException(
|
|
124
|
+
status_code=status.HTTP_400_BAD_REQUEST,
|
|
125
|
+
detail="At least one of the following query parameters must be provided: partner_ref, project_id, partner_phone", # noqa E501
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
domain = []
|
|
129
|
+
if partner_ref:
|
|
130
|
+
partner = get_partner_by_ref(env, partner_ref)
|
|
131
|
+
domain += [("partner_id", "=", partner.id)]
|
|
132
|
+
if project_id:
|
|
133
|
+
domain += [("project_id", "=", project_id)]
|
|
134
|
+
if partner_phone:
|
|
135
|
+
domain += [("partner_phone", "=", partner_phone)]
|
|
136
|
+
|
|
137
|
+
records = env["project.task"].sudo().search(domain)
|
|
138
|
+
if not records:
|
|
139
|
+
raise HTTPException(
|
|
140
|
+
status_code=status.HTTP_404_NOT_FOUND,
|
|
141
|
+
detail="Project task record not found",
|
|
142
|
+
)
|
|
143
|
+
return [serialize_record(record, ProjectTaskPresenter) for record in records]
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@project_task_router.post(
|
|
147
|
+
"",
|
|
148
|
+
response_model=ProjectTaskPresenter,
|
|
149
|
+
status_code=status.HTTP_201_CREATED,
|
|
150
|
+
)
|
|
151
|
+
def create_project_task(
|
|
152
|
+
partner: Annotated[Partner, Depends(authenticated_partner_by_api_key)],
|
|
153
|
+
env: Annotated[Environment, Depends(odoo_env)],
|
|
154
|
+
payload: ProjectTaskCreatePayload,
|
|
155
|
+
) -> ProjectTaskPresenter:
|
|
156
|
+
params = {k: v for k, v in payload.model_dump().items() if v is not None}
|
|
157
|
+
params.pop("documents", None)
|
|
158
|
+
project = get_project_by_code(env, params.pop("project_code"))
|
|
159
|
+
|
|
160
|
+
params.update(get_partner_and_contract_params(env, params))
|
|
161
|
+
params["project_id"] = project.id
|
|
162
|
+
|
|
163
|
+
if params.get("properties"):
|
|
164
|
+
project_properties = project.task_properties_definition
|
|
165
|
+
project_properties_names = [prop["name"] for prop in project_properties]
|
|
166
|
+
unknown_properties = set(params["properties"]) - set(project_properties_names)
|
|
167
|
+
if unknown_properties:
|
|
168
|
+
raise HTTPException(
|
|
169
|
+
status_code=status.HTTP_400_BAD_REQUEST,
|
|
170
|
+
detail="Unknown property {} for this task: {}".format(
|
|
171
|
+
"y" if len(unknown_properties) == 1 else "ies",
|
|
172
|
+
", ".join(sorted(unknown_properties)),
|
|
173
|
+
),
|
|
174
|
+
)
|
|
175
|
+
params["task_properties"] = params["properties"]
|
|
176
|
+
del params["properties"]
|
|
177
|
+
|
|
178
|
+
try:
|
|
179
|
+
record = env["project.task"].sudo().create(params)
|
|
180
|
+
attach_documents(env, record.id, payload.documents)
|
|
181
|
+
except Exception as exc:
|
|
182
|
+
raise HTTPException(
|
|
183
|
+
status_code=status.HTTP_400_BAD_REQUEST,
|
|
184
|
+
detail=str(exc),
|
|
185
|
+
) from exc
|
|
186
|
+
return serialize_record(record, ProjectTaskPresenter)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@project_task_router.get("/{record_id:int}", response_model=ProjectTaskPresenter)
|
|
190
|
+
def get_project_task(
|
|
191
|
+
partner: Annotated[Partner, Depends(authenticated_partner_by_api_key)],
|
|
192
|
+
env: Annotated[Environment, Depends(odoo_env)],
|
|
193
|
+
record_id: int,
|
|
194
|
+
) -> ProjectTaskPresenter:
|
|
195
|
+
record = env["project.task"].sudo().browse(record_id)
|
|
196
|
+
if not record.exists():
|
|
197
|
+
raise HTTPException(
|
|
198
|
+
status_code=status.HTTP_404_NOT_FOUND,
|
|
199
|
+
detail="Project task record with id {} not found".format(record_id),
|
|
200
|
+
)
|
|
201
|
+
return serialize_record(record, ProjectTaskPresenter)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
@project_task_router.put("/{record_id:int}", response_model=ProjectTaskPresenter)
|
|
205
|
+
def update_project_task(
|
|
206
|
+
partner: Annotated[Partner, Depends(authenticated_partner_by_api_key)],
|
|
207
|
+
env: Annotated[Environment, Depends(odoo_env)],
|
|
208
|
+
record_id: int,
|
|
209
|
+
payload: ProjectTaskUpdatePayload,
|
|
210
|
+
) -> ProjectTaskPresenter:
|
|
211
|
+
record = env["project.task"].sudo().browse(record_id)
|
|
212
|
+
if not record.exists():
|
|
213
|
+
raise HTTPException(
|
|
214
|
+
status_code=status.HTTP_404_NOT_FOUND,
|
|
215
|
+
detail="Project task record with id {} not found".format(record_id),
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
params = {
|
|
219
|
+
k: v
|
|
220
|
+
for k, v in payload.model_dump().items()
|
|
221
|
+
if v is not None and k != "properties"
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
params.update(get_partner_and_contract_params(env, params))
|
|
225
|
+
|
|
226
|
+
if params.get("project_code"):
|
|
227
|
+
params["project_id"] = get_project_by_code(env, params.pop("project_code")).id
|
|
228
|
+
|
|
229
|
+
if payload.properties:
|
|
230
|
+
current_properties = {
|
|
231
|
+
prop["name"]: prop["value"] for prop in record.task_properties or []
|
|
232
|
+
}
|
|
233
|
+
unknown_properties = set(payload.properties) - set(current_properties)
|
|
234
|
+
if unknown_properties:
|
|
235
|
+
raise HTTPException(
|
|
236
|
+
status_code=status.HTTP_400_BAD_REQUEST,
|
|
237
|
+
detail="Unknown property {} for this task: {}".format(
|
|
238
|
+
"y" if len(unknown_properties) == 1 else "ies",
|
|
239
|
+
", ".join(sorted(unknown_properties)),
|
|
240
|
+
),
|
|
241
|
+
)
|
|
242
|
+
current_properties.update(payload.properties)
|
|
243
|
+
params["task_properties"] = current_properties
|
|
244
|
+
|
|
245
|
+
try:
|
|
246
|
+
record.write(params)
|
|
247
|
+
except Exception as exc:
|
|
248
|
+
raise HTTPException(
|
|
249
|
+
status_code=status.HTTP_400_BAD_REQUEST,
|
|
250
|
+
detail=str(exc),
|
|
251
|
+
) from exc
|
|
252
|
+
|
|
253
|
+
return serialize_record(record, ProjectTaskPresenter)
|