From 08fe32272ed3208ab1c90d16b5531059b3a50cdd Mon Sep 17 00:00:00 2001
From: Antoine Vandevenne <anv@odoo.com>
Date: Wed, 24 Nov 2021 14:30:14 +0100
Subject: [PATCH] [FIX] payment: don't display token in error message

This is internal data that does not need to be shown to the user
---
 addons/payment/models/account_invoice.py | 6 +++---
 addons/sale/models/sale.py               | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/addons/payment/models/account_invoice.py b/addons/payment/models/account_invoice.py
index 1b91cdf656a2..75c12a339832 100644
--- a/addons/payment/models/account_invoice.py
+++ b/addons/payment/models/account_invoice.py
@@ -52,12 +52,12 @@ class AccountMove(models.Model):
                 if payment_token and payment_token.acquirer_id != acquirer:
                     raise ValidationError(_('Invalid token found! Token acquirer %s != %s') % (
                     payment_token.acquirer_id.name, acquirer.name))
-                if payment_token and payment_token.partner_id != partner:
-                    raise ValidationError(_('Invalid token found! Token partner %s != %s') % (
-                    payment_token.partner.name, partner.name))
             else:
                 acquirer = payment_token.acquirer_id
 
+            if payment_token and payment_token.partner_id != partner:
+                raise ValidationError(_('Invalid token found!'))
+
         # Check an acquirer is there.
         if not acquirer_id and not acquirer:
             raise ValidationError(_('A payment acquirer is required to create a transaction.'))
diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py
index 6a302a239359..579317d6c950 100644
--- a/addons/sale/models/sale.py
+++ b/addons/sale/models/sale.py
@@ -962,12 +962,12 @@ class SaleOrder(models.Model):
                 if payment_token and payment_token.acquirer_id != acquirer:
                     raise ValidationError(_('Invalid token found! Token acquirer %s != %s') % (
                     payment_token.acquirer_id.name, acquirer.name))
-                if payment_token and payment_token.partner_id != partner:
-                    raise ValidationError(_('Invalid token found! Token partner %s != %s') % (
-                    payment_token.partner.name, partner.name))
             else:
                 acquirer = payment_token.acquirer_id
 
+            if payment_token and payment_token.partner_id != partner:
+                raise ValidationError(_('Invalid token found!'))
+
         # Check an acquirer is there.
         if not acquirer_id and not acquirer:
             raise ValidationError(_('A payment acquirer is required to create a transaction.'))
-- 
GitLab