After the payment apocalypse, `payment_test` was cleaned and stripped of all useless parts. It was a very basic testing acquirer that allowed to enter fake arbitrary payment details, choose whether they should be tokenized, and then pay. It was intended to test the payment flow of various applications (Sales, Subscriptions, Invoicing, ...) for a single scenario: successful payments with immediate capture. In order to extensively test an app's payment flow (explore other scenarios), we need `payment_test` to have additional features. Now, `payment_test` will allow profound testing of these features: - separate authorization and capture - customer fees computation - tokenization - refunds - on the /pay page, users will be able to select the status of the payment - on the payment transaction form view, users can change the status of a payment 'pending' to either succeed or fail - on the payment token form view, users can change the state of future transactions made with that token task-2512196 closes odoo/odoo#78083 Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com> Co-authored-by: xlu-odoo <xlu@odoo.com>
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import _, api, fields, models
|
|
from odoo.exceptions import UserError
|
|
|
|
|
|
class PaymentAcquirer(models.Model):
|
|
_inherit = 'payment.acquirer'
|
|
|
|
provider = fields.Selection(selection_add=[('test', 'Test')], ondelete={'test': 'set default'})
|
|
|
|
#=== COMPUTE METHODS ===#
|
|
|
|
@api.depends('provider')
|
|
def _compute_view_configuration_fields(self):
|
|
""" Override of payment to hide the credentials page.
|
|
|
|
:return: None
|
|
"""
|
|
super()._compute_view_configuration_fields()
|
|
self.filtered(lambda acq: acq.provider == 'test').show_credentials_page = False
|
|
|
|
def _compute_feature_support_fields(self):
|
|
""" Override of `payment` to enable additional features. """
|
|
super()._compute_feature_support_fields()
|
|
self.filtered(lambda acq: acq.provider == 'test').update({
|
|
'support_fees': True,
|
|
'support_manual_capture': True,
|
|
'support_refund': 'partial',
|
|
'support_tokenization': True,
|
|
})
|
|
|
|
# === CONSTRAINT METHODS ===#
|
|
|
|
@api.constrains('state', 'provider')
|
|
def _check_acquirer_state(self):
|
|
if self.filtered(lambda a: a.provider == 'test' and a.state not in ('test', 'disabled')):
|
|
raise UserError(_("Test acquirers should never be enabled."))
|
|
|
|
def _get_default_payment_method_id(self):
|
|
self.ensure_one()
|
|
if self.provider != 'test':
|
|
return super()._get_default_payment_method_id()
|
|
return self.env.ref('payment_test.payment_method_test').id
|