[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.
This commit is contained in:
Stéphan Sainléger
2026-11-09 00:21:02 +01:00
parent b6c7055091
commit 82971af4d4
4 changed files with 61 additions and 5 deletions

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)