Files
project-tools/project_average_acceptable_time/controllers/custom_portal.py
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

31 lines
1.2 KiB
Python

# Copyright 2020 Lokavaluto ()
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.http import request, route
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):
response = super().account(redirect, **post)
if post and request.httprequest.method == "POST":
error, error_message = self.details_form_validate(post)
if not error:
# sudo: a portal user has no write access at all on
# 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"
]
return response