63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import logging
|
|
|
|
from odoo import _, api, fields, models
|
|
|
|
from odoo.addons.payment_paypal.const import SUPPORTED_CURRENCIES
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class PaymentProvider(models.Model):
|
|
_inherit = 'payment.provider'
|
|
|
|
code = fields.Selection(
|
|
selection_add=[('paypal', "Paypal")], ondelete={'paypal': 'set default'})
|
|
paypal_email_account = fields.Char(
|
|
string="Email",
|
|
help="The public business email solely used to identify the account with PayPal",
|
|
required_if_provider='paypal')
|
|
paypal_seller_account = fields.Char(
|
|
string="Merchant Account ID", groups='base.group_system')
|
|
paypal_pdt_token = fields.Char(string="PDT Identity Token", groups='base.group_system')
|
|
paypal_use_ipn = fields.Boolean(
|
|
string="Use IPN", help="Paypal Instant Payment Notification", default=True)
|
|
|
|
#=== COMPUTE METHODS ===#
|
|
|
|
def _compute_feature_support_fields(self):
|
|
""" Override of `payment` to enable additional features. """
|
|
super()._compute_feature_support_fields()
|
|
self.filtered(lambda p: p.code == 'paypal').update({
|
|
'support_fees': True,
|
|
})
|
|
|
|
#=== BUSINESS METHODS ===#
|
|
|
|
@api.model
|
|
def _get_compatible_providers(self, *args, currency_id=None, **kwargs):
|
|
""" Override of payment to unlist PayPal providers when the currency is not supported. """
|
|
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 != 'paypal')
|
|
|
|
return providers
|
|
|
|
def _paypal_get_api_url(self):
|
|
""" Return the API URL according to the provider state.
|
|
|
|
Note: self.ensure_one()
|
|
|
|
:return: The API URL
|
|
:rtype: str
|
|
"""
|
|
self.ensure_one()
|
|
|
|
if self.state == 'enabled':
|
|
return 'https://www.paypal.com/cgi-bin/webscr'
|
|
else:
|
|
return 'https://www.sandbox.paypal.com/cgi-bin/webscr'
|