Before this commit, the lists of supported currencies by payment provider were hard-coded in the Python scripts, which made them unavailable to the users. With this commit, the implemented initial lists of supported currencies are displayed on the form view and are editable, because Odoo lists may not be up-to-date. Empty lists do not trigger any filtering on the payment providers to access payment methods. For Authorize.net and Asiapay payment providers, the specific `(authorize,asiapay)_currency_id` are removed and the generic payment provider field `available_currency_ids` is restricted to a single-item list when one of those providers is enabled. task-2926016 closes odoo/odoo#101018 Related: odoo/enterprise#34158 Related: odoo/documentation#2788 Related: odoo/upgrade#4069 Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
78 lines
2.8 KiB
Python
78 lines
2.8 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import logging
|
|
|
|
from odoo import _, 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 ===#
|
|
|
|
def _get_supported_currencies(self):
|
|
""" Override of `payment` to return the supported currencies. """
|
|
supported_currencies = super()._get_supported_currencies()
|
|
if self.code == 'paypal':
|
|
supported_currencies = supported_currencies.filtered(
|
|
lambda c: c.name in SUPPORTED_CURRENCIES
|
|
)
|
|
return supported_currencies
|
|
|
|
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'
|
|
|
|
def _paypal_send_configuration_reminder(self):
|
|
render_template = self.env['ir.qweb']._render(
|
|
'payment_paypal.mail_template_paypal_invite_user_to_configure',
|
|
{'provider': self},
|
|
raise_if_not_found=False,
|
|
)
|
|
if render_template:
|
|
mail_body = self.env['mail.render.mixin']._replace_local_links(render_template)
|
|
mail_values = {
|
|
'body_html': mail_body,
|
|
'subject': _("Add your PayPal account to Odoo"),
|
|
'email_to': self.paypal_email_account,
|
|
'email_from': self.create_uid.email_formatted,
|
|
'author_id': self.create_uid.partner_id.id,
|
|
}
|
|
self.env['mail.mail'].sudo().create(mail_values).send()
|