test_payment_flows.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. from odoo.tests import tagged
  3. from odoo.tools import mute_logger
  4. from odoo.addons.payment.tests.http_common import PaymentHttpCommon
  5. from odoo.addons.account_payment.tests.common import AccountPaymentCommon
  6. @tagged('post_install', '-at_install')
  7. class TestFlows(AccountPaymentCommon, PaymentHttpCommon):
  8. def test_invoice_payment_flow(self):
  9. """Test the payment of an invoice through the payment/pay route"""
  10. # Pay for this invoice (no impact even if amounts do not match)
  11. route_values = self._prepare_pay_values()
  12. route_values['invoice_id'] = self.invoice.id
  13. tx_context = self._get_tx_checkout_context(**route_values)
  14. self.assertEqual(tx_context['invoice_id'], self.invoice.id)
  15. # payment/transaction
  16. route_values = {
  17. k: tx_context[k]
  18. for k in [
  19. 'amount',
  20. 'currency_id',
  21. 'reference_prefix',
  22. 'partner_id',
  23. 'access_token',
  24. 'landing_route',
  25. 'invoice_id',
  26. ]
  27. }
  28. route_values.update({
  29. 'flow': 'direct',
  30. 'payment_option_id': self.provider.id,
  31. 'tokenization_requested': False,
  32. })
  33. with mute_logger('odoo.addons.payment.models.payment_transaction'):
  34. processing_values = self._get_processing_values(**route_values)
  35. tx_sudo = self._get_tx(processing_values['reference'])
  36. # Note: strangely, the check
  37. # self.assertEqual(tx_sudo.invoice_ids, invoice)
  38. # doesn't work, and cache invalidation doesn't work either.
  39. self.invoice.invalidate_recordset(['transaction_ids'])
  40. self.assertEqual(self.invoice.transaction_ids, tx_sudo)