Files
odoo_source/addons/payment_custom/models/payment_transaction.py
T
Horacio Tellez f7b8f07501 [IMP] payment: rename of acquirer to provider
Changing the name of model payment.acquirer to payment.provider
and everything that it touches. It is technically incorrect to
use the term "acquirer" for systems that only provide a service
of payment.
After this commit the model payment.acquirer and all related to
it will be renamed to payment.provider.

Task - 2842088

closes odoo/odoo#90899

Related: odoo/upgrade#3542
Related: odoo/documentation#1981
Related: odoo/enterprise#27131
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2022-09-09 13:38:08 +02:00

94 lines
3.3 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
from odoo import _, api, models
from odoo.exceptions import ValidationError
from odoo.addons.payment_custom.controllers.main import CustomController
_logger = logging.getLogger(__name__)
class PaymentTransaction(models.Model):
_inherit = 'payment.transaction'
def _get_specific_rendering_values(self, processing_values):
""" Override of payment to return custom-specific rendering values.
Note: self.ensure_one() from `_get_processing_values`
:param dict processing_values: The generic and specific processing values of the transaction
:return: The dict of provider-specific processing values
:rtype: dict
"""
res = super()._get_specific_rendering_values(processing_values)
if self.provider_code != 'custom':
return res
return {
'api_url': CustomController._process_url,
'reference': self.reference,
}
def _get_tx_from_notification_data(self, provider_code, notification_data):
""" Override of payment to find the transaction based on custom data.
:param str provider_code: The code of the provider that handled the transaction
:param dict notification_data: The notification feedback data
:return: The transaction if found
:rtype: recordset of `payment.transaction`
:raise: ValidationError if the data match no transaction
"""
tx = super()._get_tx_from_notification_data(provider_code, notification_data)
if provider_code != 'custom' or len(tx) == 1:
return tx
reference = notification_data.get('reference')
tx = self.search([('reference', '=', reference), ('provider_code', '=', 'custom')])
if not tx:
raise ValidationError(
"Wire Transfer: " + _("No transaction found matching reference %s.", reference)
)
return tx
def _process_notification_data(self, notification_data):
""" Override of payment to process the transaction based on custom data.
Note: self.ensure_one()
:param dict notification_data: The custom data
:return: None
"""
super()._process_notification_data(notification_data)
if self.provider_code != 'custom':
return
_logger.info(
"validated custom payment for transaction with reference %s: set as pending",
self.reference
)
self._set_pending()
def _log_received_message(self):
""" Override of `payment` to remove custom providers from the recordset.
:return: None
"""
other_provider_txs = self.filtered(lambda t: t.provider_code != 'custom')
super(PaymentTransaction, other_provider_txs)._log_received_message()
def _get_sent_message(self):
""" Override of payment to return a different message.
:return: The 'transaction sent' message
:rtype: str
"""
message = super()._get_sent_message()
if self.provider_code == 'custom':
message = _(
"The customer has selected %(provider_name)s to make the payment.",
provider_name=self.provider_id.name
)
return message