[MIG] payment_forte: to 15.0, changes to make tests work (WIP)

H4431
This commit is contained in:
Jorge Che
2022-06-08 15:51:00 +00:00
parent 168661d1ec
commit d05d2b8042
5 changed files with 51 additions and 21 deletions

View File

@@ -13,5 +13,17 @@
<field name="forte_secure_key">dummy</field>
</record>
<record id="payment_method_forte_echeck_inbound" model="account.payment.method">
<field name="name">Forte eCheck</field>
<field name="code">forte</field>
<field name="payment_type">inbound</field>
</record>
<record id="payment_method_forte_echeck_outbound" model="account.payment.method">
<field name="name">Forte eCheck</field>
<field name="code">forte</field>
<field name="payment_type">outbound</field>
</record>
</data>
</odoo>

View File

@@ -1 +1,2 @@
from . import payment
from . import account_payment_method

View File

@@ -0,0 +1,11 @@
from odoo import api, models
class AccountPaymentMethod(models.Model):
_inherit = 'account.payment.method'
@api.model
def _get_payment_method_information(self):
res = super()._get_payment_method_information()
res['forte'] = {'mode': 'unique', 'domain': [('type', '=', 'bank')]}
return res

View File

@@ -56,24 +56,41 @@ class AccountPayment(models.Model):
def _do_payment(self):
self = self.with_context(payment_type=self.payment_type)
return super(AccountPayment, self)._do_payment()
return super(AccountPayment, self)._do_payment(payment_type=self.payment_type)
class TxForte(models.Model):
_inherit = 'payment.transaction'
def _send_payment_request(self):
""" Override of payment to send a payment request to Authorize.
Note: self.ensure_one()
:return: None
:raise: UserError if the transaction is not linked to a token
"""
super()._send_payment_request()
if self.provider != 'forte':
return
res = self.forte_s2s_do_transaction()
def forte_s2s_do_transaction(self, **data):
self.ensure_one()
api = forte_get_api(self.acquirer_id)
location = self.acquirer_id.forte_location_id
amount = self.amount
account_type = self.payment_token_id.forte_account_type
routing_number = self.payment_token_id.forte_routing_number
account_number = self.payment_token_id.forte_account_number
account_holder = self.payment_token_id.forte_account_holder
account_type = self.token_id.forte_account_type
routing_number = self.token_id.forte_routing_number
account_number = self.token_id.forte_account_number
account_holder = self.token_id.forte_account_holder
if not self.env.context.get('payment_type'):
_logger.warn('Trying to do a payment with Forte and no contextual payment_type will result in an inbound transaction.')
if self.env.context.get('payment_type', 'inbound') == 'inbound':
_logger.warning('Trying to do a payment with Forte and no contextual payment_type will result in an inbound transaction.')
if self.env.context.get('payment_type') == 'inbound':
resp = api.echeck_sale(location, amount, account_type, routing_number, account_number, account_holder)
else:
resp = api.echeck_credit(location, amount, account_type, routing_number, account_number, account_holder)
@@ -119,14 +136,3 @@ class PaymentToken(models.Model):
forte_routing_number = fields.Char(string='Forte Routing Number', help='e.g. 021000021')
forte_account_number = fields.Char(string='Forte Account Number', help='e.g. 000111222')
forte_account_holder = fields.Char(string='Forte Account Holder', help='e.g. John Doe')
# Boilerplate for views
provider = fields.Selection(string='Provider', related='acquirer_id.provider')
@api.model
def forte_create(self, values):
if values.get('forte_account_number'):
#acquirer = self.env['payment.acquirer'].browse(values['acquirer_id'])
#partner = self.env['res.partner'].browse(values['partner_id'])
# eventually check the types and account numbers
pass
return values

View File

@@ -1,8 +1,6 @@
from odoo.addons.payment.tests.common import PaymentCommon
from odoo.exceptions import ValidationError
from odoo.tests import tagged
class ForteCommon(PaymentCommon):
@classmethod
@@ -22,7 +20,7 @@ class ForteCommon(PaymentCommon):
cls.acquirer = cls.forte
cls.currency = cls.currency_usd
cls.forte = cls.acquirer
cls.method = cls.env['account.payment.method'].search([('code', '=', 'electronic')], limit=1)[0]
cls.method = cls.env.ref('payment_forte.payment_method_forte_echeck_inbound')
cls.journal = cls.env['account.journal'].search([], limit=1)[0]
cls.journal.write({
'inbound_payment_method_line_ids': [(0, 0, {
@@ -65,6 +63,8 @@ class ForteACH(ForteCommon):
'payment_method_line_id': self.method_line.id,
'amount': 22.00,
})
payment.action_post()
self.assertTrue(payment.payment_transaction_id)
self.assertEqual(payment.payment_transaction_id.amount, 22.00)
self.assertTrue(payment.payment_transaction_id.acquirer_reference)