This commit adds the possibility to define a maximum payment amount that a given acquirer can process. If the payment amount exceeds the value, the acquirer is filtered out of the available acquirers listed on the payment forms. While we're at it, the field `country_ids` is renamed to `available_country_ids` to better depict that it is not a property of the acquirer, but a configuration option. It will also be coherent with the field `available_currency_ids` that is expected to be added soon. Task - 2162165 closes odoo/odoo#82411 Related: odoo/enterprise#24412 Related: odoo/upgrade#3703 Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
70 lines
3.1 KiB
Python
70 lines
3.1 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.tests import tagged
|
|
|
|
from odoo.addons.payment.tests.common import PaymentCommon
|
|
|
|
|
|
@tagged('-at_install', 'post_install')
|
|
class TestPaymentAcquirer(PaymentCommon):
|
|
|
|
def test_published_acquirer_compatible_with_all_users(self):
|
|
""" Test that a published acquirer is always available to all users. """
|
|
for user in (self.public_user, self.portal_user):
|
|
self.env = self.env(user=user)
|
|
|
|
compatible_acquirers = self.env['payment.acquirer'].sudo()._get_compatible_acquirers(
|
|
self.company.id, self.partner.id, self.amount
|
|
)
|
|
self.assertIn(self.acquirer, compatible_acquirers)
|
|
|
|
def test_unpublished_acquirer_compatible_with_internal_user(self):
|
|
""" Test that an unpublished acquirer is still available to internal users. """
|
|
self.acquirer.is_published = False
|
|
|
|
compatible_acquirers = self.env['payment.acquirer']._get_compatible_acquirers(
|
|
self.company.id, self.partner.id, self.amount
|
|
)
|
|
self.assertIn(self.acquirer, compatible_acquirers)
|
|
|
|
def test_unpublished_acquirer_not_compatible_with_non_internal_user(self):
|
|
""" Test that an unpublished acquirer is not available to non-internal users. """
|
|
self.acquirer.is_published = False
|
|
for user in (self.public_user, self.portal_user):
|
|
self.env = self.env(user=user)
|
|
|
|
compatible_acquirers = self.env['payment.acquirer'].sudo()._get_compatible_acquirers(
|
|
self.company.id, self.partner.id, self.amount
|
|
)
|
|
self.assertNotIn(self.acquirer, compatible_acquirers)
|
|
|
|
def test_acquirer_compatible_when_maximum_amount_is_zero(self):
|
|
""" Test that the maximum amount has no effect on the acquirer's compatibility when it is
|
|
set to 0. """
|
|
self.acquirer.maximum_amount = 0.
|
|
|
|
compatible_acquirers = self.acquirer._get_compatible_acquirers(
|
|
self.company.id, self.partner.id, self.amount, currency_id=self.currency.id
|
|
)
|
|
self.assertIn(self.acquirer, compatible_acquirers)
|
|
|
|
def test_acquirer_compatible_when_payment_below_maximum_amount(self):
|
|
""" Test that an acquirer is compatible when the payment amount is less than the maximum
|
|
amount. """
|
|
self.acquirer.maximum_amount = self.amount + 10.0
|
|
|
|
compatible_acquirers = self.acquirer._get_compatible_acquirers(
|
|
self.company.id, self.partner.id, self.amount, currency_id=self.currency.id
|
|
)
|
|
self.assertIn(self.acquirer, compatible_acquirers)
|
|
|
|
def test_acquirer_not_compatible_when_payment_above_maximum_amount(self):
|
|
""" Test that an acquirer is not compatible when the payment amount is more than the maximum
|
|
amount. """
|
|
self.acquirer.maximum_amount = self.amount - 10.0
|
|
|
|
compatible_acquirers = self.acquirer._get_compatible_acquirers(
|
|
self.company.id, self.partner.id, self.amount, currency_id=self.currency.id
|
|
)
|
|
self.assertNotIn(self.acquirer, compatible_acquirers)
|