The portal override validated the submitted data a second time after ``super().account()`` returned. When the partner cannot edit its VAT (child contact or issued invoices), the country select is disabled and not submitted; Odoo core injects the missing ``country_id`` in its own copy of the posted data, but the raw payload re-validated by the module still lacked it, raising ``KeyError: 'country_id'`` and a 500 on save. Move the default-project update to ``on_account_update()``, which Odoo calls after a successful validation, and drop the duplicate validation. Add a regression test with a child contact whose country field is disabled.
25 lines
1.0 KiB
Python
25 lines
1.0 KiB
Python
# Copyright 2020 Lokavaluto ()
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
from odoo.http import request
|
|
|
|
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
|
|
|
|
def on_account_update(self, values, partner):
|
|
res = super().on_account_update(values, partner)
|
|
average_acceptable_time = values.get("average_acceptable_time")
|
|
if average_acceptable_time:
|
|
# 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:
|
|
project_sudo.average_acceptable_time = average_acceptable_time
|
|
return res
|