[IMP] payment_demo: add support partial capture

support partial capture feature in demo payment
task-2803352

closes odoo/odoo#117356

Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
This commit is contained in:
Valeriya(vchu)
2023-05-05 17:06:13 +02:00
parent e1f0811b22
commit ff64df758b
3 changed files with 27 additions and 5 deletions
@@ -25,7 +25,7 @@ class PaymentProvider(models.Model):
super()._compute_feature_support_fields()
self.filtered(lambda p: p.code == 'demo').update({
'support_fees': True,
'support_manual_capture': 'full_only',
'support_manual_capture': 'partial',
'support_refund': 'partial',
'support_tokenization': True,
})
@@ -103,12 +103,13 @@ class PaymentTransaction(models.Model):
if self.provider_code != 'demo':
return child_capture_tx
tx = child_capture_tx or self
notification_data = {
'reference': self.reference,
'reference': tx.reference,
'simulated_state': 'done',
'manual_capture': True, # Distinguish manual captures from regular one-step captures.
}
self._handle_notification_data('demo', notification_data)
tx._handle_notification_data('demo', notification_data)
return child_capture_tx
@@ -118,8 +119,9 @@ class PaymentTransaction(models.Model):
if self.provider_code != 'demo':
return child_void_tx
notification_data = {'reference': self.reference, 'simulated_state': 'cancel'}
self._handle_notification_data('demo', notification_data)
tx = child_void_tx or self
notification_data = {'reference': tx.reference, 'simulated_state': 'cancel'}
tx._handle_notification_data('demo', notification_data)
return child_void_tx
@@ -80,3 +80,23 @@ class TestPaymentTransaction(PaymentDemoCommon, PaymentHttpCommon):
tx.token_id = self._create_token(demo_simulated_state=state)
tx._send_payment_request()
self.assertEqual(tx.state, tx.token_id.demo_simulated_state)
def test_send_full_capture_request_does_not_create_capture_tx(self):
self.provider.capture_manually = True
source_tx = self._create_transaction(flow='direct', state='authorized')
child_tx = source_tx._send_capture_request()
self.assertFalse(
child_tx, msg="Full capture should not create a child transaction."
)
def test_send_partial_capture_request_creates_capture_tx(self):
self.provider.capture_manually = True
source_tx = self._create_transaction(flow='direct', state='authorized')
child_tx = source_tx._send_capture_request(amount_to_capture=10)
self.assertTrue(
source_tx.child_transaction_ids,
msg="Partial capture should create a child transaction and linked it to the source tx.",
)
self.assertEqual(
child_tx.amount, 10, msg="Child transaction should have the requested amount."
)