2 Commits

Author SHA1 Message Date
Stéphan Sainléger
533e12d376 [REF] project_average_acceptable_time: read posted value once
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m30s
tests / test (pull_request) Successful in 2m0s
The portal override looked the custom field up twice, once with ``get()``
for the condition and once with ``[]`` for the assignment. Read it once so
the code stays safe if the input is absent from the submitted form.
2026-11-09 00:33:08 +01:00
Stéphan Sainléger
82971af4d4 [FIX] project_average_acceptable_time: use Odoo 18 optional fields API
Odoo 18 replaced the ``OPTIONAL_BILLING_FIELDS`` class attribute with the
``_get_optional_fields()`` method. The portal controller still appended to
the removed attribute, raising ``AttributeError`` on every request to
``/my/account`` and making the page unavailable to all portal users.

Override ``_get_optional_fields()`` instead, as ``elabore_subscription_price``
already does, and add HTTP tests covering the page load and the default
project update on form submission.
2026-11-09 00:21:02 +01:00
4 changed files with 64 additions and 9 deletions

View File

@@ -3,7 +3,7 @@
{
"name": "project_average_acceptable_time",
"version": "18.0.1.1.0",
"version": "18.0.1.1.1",
"author": "Elabore",
"website": "https://git.elabore.coop/elabore/project-tools",
"maintainer": "Clément Thomas",

View File

@@ -6,12 +6,13 @@ from odoo.addons.portal.controllers.portal import CustomerPortal
class CustomCustomerPortal(CustomerPortal):
def _get_optional_fields(self):
return super()._get_optional_fields() + [
"average_acceptable_time"
] # unnecessary save in res partner, but necessary to avoid error on form post
@route(["/my/account"], type="http", auth="user", website=True)
def account(self, redirect=None, **post):
self.OPTIONAL_BILLING_FIELDS.append(
"average_acceptable_time"
) # unecessary save in res partner, but necessary to avoid error on form post
response = super().account(redirect, **post)
if post and request.httprequest.method == "POST":
@@ -21,9 +22,8 @@ class CustomCustomerPortal(CustomerPortal):
# project.project, and no read access on its default project
# unless it follows it
project_sudo = request.env.user.sudo().default_project_id
if project_sudo and post.get("average_acceptable_time"):
project_sudo.average_acceptable_time = post[
"average_acceptable_time"
]
average_acceptable_time = post.get("average_acceptable_time")
if project_sudo and average_acceptable_time:
project_sudo.average_acceptable_time = average_acceptable_time
return response

View File

@@ -0,0 +1 @@
from . import test_portal_account

View File

@@ -0,0 +1,54 @@
# Copyright 2026 Stéphan Sainléger (Elabore)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.http import Request
from odoo.tests import HttpCase, tagged
from odoo.addons.mail.tests.common import mail_new_test_user
@tagged("-at_install", "post_install")
class TestPortalAccountAverageAcceptableTime(HttpCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.project = cls.env["project.project"].create(
{"name": "Portal average acceptable time"}
)
cls.portal_user = mail_new_test_user(
cls.env,
login="portal_average_acceptable_time",
name="Portal Average Acceptable Time",
groups="base.group_portal",
default_project_id=cls.project.id,
)
def _account_form_data(self, **overrides):
data = {
"name": self.portal_user.partner_id.name,
"email": self.portal_user.partner_id.email,
"phone": "+33123456789",
"street": "1 rue de la Paix",
"city": "Paris",
"zipcode": "75002",
"country_id": self.env.ref("base.fr").id,
"csrf_token": Request.csrf_token(self),
}
data.update(overrides)
return data
def test_account_page_renders(self):
"""The portal account page must load for a portal user."""
self.authenticate(self.portal_user.login, self.portal_user.login)
response = self.url_open("/my/account")
self.assertEqual(response.status_code, 200)
def test_account_post_updates_default_project(self):
"""Posting the form must store the value on the default project."""
self.authenticate(self.portal_user.login, self.portal_user.login)
response = self.url_open(
"/my/account",
data=self._account_form_data(average_acceptable_time="1.5"),
)
self.assertEqual(response.status_code, 200)
self.project.invalidate_recordset()
self.assertEqual(self.project.average_acceptable_time, 1.5)