|
| 1 | +# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 | + |
| 3 | +from odoo.tests import tagged |
| 4 | + |
| 5 | +from odoo.addons.payment.tests.common import PaymentCommon |
| 6 | + |
| 7 | + |
| 8 | +@tagged('post_install', '-at_install') |
| 9 | +class TestPaymentCaptureWizard(PaymentCommon): |
| 10 | + |
| 11 | + def test_partial_capture_wizard(self): |
| 12 | + self.provider.update({ |
| 13 | + 'capture_manually': True, |
| 14 | + 'support_manual_capture': 'partial', |
| 15 | + }) |
| 16 | + source_tx = self._create_transaction('direct', state='authorized') |
| 17 | + |
| 18 | + wizard = self.env['payment.capture.wizard'].create({ |
| 19 | + 'transaction_ids': source_tx.ids, |
| 20 | + }) |
| 21 | + wizard.amount_to_capture = 511.11 |
| 22 | + wizard.action_capture() |
| 23 | + |
| 24 | + child_tx_1 = source_tx.child_transaction_ids |
| 25 | + self.assertEqual(child_tx_1.state, 'draft') |
| 26 | + child_tx_1._set_done() |
| 27 | + |
| 28 | + self.env['payment.capture.wizard'].create({ |
| 29 | + 'transaction_ids': source_tx.ids, |
| 30 | + }).action_capture() |
| 31 | + |
| 32 | + child_tx_2 = (source_tx.child_transaction_ids - child_tx_1).ensure_one() |
| 33 | + child_tx_2._set_done() |
| 34 | + self.assertAlmostEqual( |
| 35 | + sum(source_tx.child_transaction_ids.mapped('amount')), |
| 36 | + source_tx.amount, |
| 37 | + ) |
| 38 | + self.assertEqual(source_tx.state, 'done') |
| 39 | + |
| 40 | + def test_support_partial_capture_computation_with_brands(self): |
| 41 | + self.provider.update({ |
| 42 | + 'capture_manually': True, |
| 43 | + 'support_manual_capture': 'partial', |
| 44 | + }) |
| 45 | + dummy_brand = self.env['payment.method'].create({ |
| 46 | + 'name': "Dummy Brand", |
| 47 | + 'code': 'dumbrand', |
| 48 | + 'primary_payment_method_id': self.payment_method.id, |
| 49 | + 'provider_ids': self.provider.ids, |
| 50 | + }) |
| 51 | + source_tx = self._create_transaction( |
| 52 | + 'direct', state='authorized', payment_method_id=dummy_brand.id, |
| 53 | + ) |
| 54 | + wizard = self.env['payment.capture.wizard'].create({ |
| 55 | + 'transaction_ids': source_tx.ids, |
| 56 | + }) |
| 57 | + self.assertTrue(wizard.support_partial_capture) |
0 commit comments