[FIX] payment: compute related_partner_ids with sudo

`related_partner_ids` is used in the form view of account.payment
https://github.com/odoo/odoo/blob/43fccd7aaa83117c95babc52d60dd1c26b28335a/addons/payment/views/account_payment_views.xml#L14
It is only needed for electronic payments to display the payment token
ids (as part of its domain)
https://github.com/odoo/odoo/blob/45f5167b956521f0a183ff1b1cc75fa1b273866c/addons/payment/models/account_payment.py#L13-L21
and for draft payments only.
https://github.com/odoo/odoo/blob/43fccd7aaa83117c95babc52d60dd1c26b28335a/addons/payment/views/account_payment_views.xml#L16

Before this change the form view will fail when partner_id has a company
that is not in the context. This is not incorrect, but it is unexpected
as `related_partner_ids` is not needed to just show the form view. A way
to reproduce the issue is to confirm a payment, then change the partner
company to a company not accessible for current user.

This causes issues during migrations: the form view for the failing
payments is displayed just fine for versions <=13.0

closes odoo/odoo#98623

X-original-commit: a126f007573a41d22108d9d7887f92b6926ef3ec
Signed-off-by: William André (wan) <wan@odoo.com>
Signed-off-by: Alvaro Fuentes Suarez (afu) <afu@odoo.com>
This commit is contained in:
Alvaro Fuentes
2022-08-22 22:56:27 +02:00
parent 1968599a45
commit adf534f2bf
+2 -1
View File
@@ -24,7 +24,8 @@ class AccountPayment(models.Model):
# == Display purpose fields ==
suitable_payment_token_ids = fields.Many2many(
comodel_name='payment.token',
compute='_compute_suitable_payment_token_ids'
compute='_compute_suitable_payment_token_ids',
compute_sudo=True,
)
# Technical field used to hide or show the payment_token_id if needed
use_electronic_payment_method = fields.Boolean(