Before this commit the neutralize system introduced in v16 was using ORM
methods in order to change appropriate records. Although flexible, this approach
could lead to call some methods with side effects while neutralizing
(eg: overloads of write).
This patch converts the neutralize system to a safer "inert" SQL based approach
by migrating the generic method _neutralize to SQL files exposed in the
data folder.
Task id: 2961687
closes odoo/odoo#102792
X-original-commit: e5dbded9bb363351feff7ca8a56c7f8a6860f492
Related: odoo/enterprise#32580
Signed-off-by: Fabien Meghazi <fme@odoo.com>
71 lines
3.0 KiB
Python
71 lines
3.0 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from hashlib import md5
|
|
|
|
from odoo import api, fields, models
|
|
from odoo.tools.float_utils import float_repr
|
|
|
|
SUPPORTED_CURRENCIES = ('ARS', 'BRL', 'CLP', 'COP', 'MXN', 'PEN', 'USD')
|
|
|
|
|
|
class PaymentProvider(models.Model):
|
|
_inherit = 'payment.provider'
|
|
|
|
code = fields.Selection(
|
|
selection_add=[('payulatam', 'PayU Latam')], ondelete={'payulatam': 'set default'})
|
|
payulatam_merchant_id = fields.Char(
|
|
string="PayU Latam Merchant ID",
|
|
help="The ID solely used to identify the account with PayULatam",
|
|
required_if_provider='payulatam')
|
|
payulatam_account_id = fields.Char(
|
|
string="PayU Latam Account ID",
|
|
help="The ID solely used to identify the country-dependent shop with PayULatam",
|
|
required_if_provider='payulatam')
|
|
payulatam_api_key = fields.Char(
|
|
string="PayU Latam API Key", required_if_provider='payulatam',
|
|
groups='base.group_system')
|
|
|
|
@api.model
|
|
def _get_compatible_providers(self, *args, currency_id=None, **kwargs):
|
|
""" Override of payment to unlist PayU Latam providers for unsupported currencies. """
|
|
providers = super()._get_compatible_providers(*args, currency_id=currency_id, **kwargs)
|
|
|
|
currency = self.env['res.currency'].browse(currency_id).exists()
|
|
if currency and currency.name not in SUPPORTED_CURRENCIES:
|
|
providers = providers.filtered(lambda p: p.code != 'payulatam')
|
|
|
|
return providers
|
|
|
|
def _payulatam_generate_sign(self, values, incoming=True):
|
|
""" Generate the signature for incoming or outgoing communications.
|
|
|
|
:param dict values: The values used to generate the signature
|
|
:param bool incoming: Whether the signature must be generated for an incoming (PayU Latam to
|
|
Odoo) or outgoing (Odoo to PayU Latam) communication.
|
|
:return: The signature
|
|
:rtype: str
|
|
"""
|
|
if incoming:
|
|
data_string = '~'.join([
|
|
self.payulatam_api_key,
|
|
self.payulatam_merchant_id,
|
|
values['referenceCode'],
|
|
# http://developers.payulatam.com/en/web_checkout/integration.html
|
|
# Section: 2. Response page > Signature validation
|
|
# PayU Latam use the "Round half to even" rounding method
|
|
# to generate their signature. This happens to be Python 3's
|
|
# default rounding method.
|
|
float_repr(float(values.get('TX_VALUE')), 1),
|
|
values['currency'],
|
|
values.get('transactionState'),
|
|
])
|
|
else:
|
|
data_string = '~'.join([
|
|
self.payulatam_api_key,
|
|
self.payulatam_merchant_id,
|
|
values['referenceCode'],
|
|
float_repr(float(values['amount']), 1),
|
|
values['currency'],
|
|
])
|
|
return md5(data_string.encode('utf-8')).hexdigest()
|