mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[MIG] payment_forte: to 15.0, changes to make tests work (WIP)
H4431
This commit is contained in:
@@ -13,5 +13,17 @@
|
|||||||
<field name="forte_secure_key">dummy</field>
|
<field name="forte_secure_key">dummy</field>
|
||||||
</record>
|
</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>
|
</data>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
from . import payment
|
from . import payment
|
||||||
|
from . import account_payment_method
|
||||||
|
|||||||
11
payment_forte/models/account_payment_method.py
Normal file
11
payment_forte/models/account_payment_method.py
Normal 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
|
||||||
@@ -56,24 +56,41 @@ class AccountPayment(models.Model):
|
|||||||
|
|
||||||
def _do_payment(self):
|
def _do_payment(self):
|
||||||
self = self.with_context(payment_type=self.payment_type)
|
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):
|
class TxForte(models.Model):
|
||||||
_inherit = 'payment.transaction'
|
_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):
|
def forte_s2s_do_transaction(self, **data):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
api = forte_get_api(self.acquirer_id)
|
api = forte_get_api(self.acquirer_id)
|
||||||
location = self.acquirer_id.forte_location_id
|
location = self.acquirer_id.forte_location_id
|
||||||
amount = self.amount
|
amount = self.amount
|
||||||
account_type = self.payment_token_id.forte_account_type
|
|
||||||
routing_number = self.payment_token_id.forte_routing_number
|
account_type = self.token_id.forte_account_type
|
||||||
account_number = self.payment_token_id.forte_account_number
|
routing_number = self.token_id.forte_routing_number
|
||||||
account_holder = self.payment_token_id.forte_account_holder
|
account_number = self.token_id.forte_account_number
|
||||||
|
account_holder = self.token_id.forte_account_holder
|
||||||
|
|
||||||
if not self.env.context.get('payment_type'):
|
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.')
|
_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') == 'inbound':
|
if self.env.context.get('payment_type') == 'inbound':
|
||||||
resp = api.echeck_sale(location, amount, account_type, routing_number, account_number, account_holder)
|
resp = api.echeck_sale(location, amount, account_type, routing_number, account_number, account_holder)
|
||||||
else:
|
else:
|
||||||
resp = api.echeck_credit(location, amount, account_type, routing_number, account_number, account_holder)
|
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_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_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')
|
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
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
from odoo.addons.payment.tests.common import PaymentCommon
|
from odoo.addons.payment.tests.common import PaymentCommon
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
from odoo.tests import tagged
|
from odoo.tests import tagged
|
||||||
|
|
||||||
|
|
||||||
class ForteCommon(PaymentCommon):
|
class ForteCommon(PaymentCommon):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -22,7 +20,7 @@ class ForteCommon(PaymentCommon):
|
|||||||
cls.acquirer = cls.forte
|
cls.acquirer = cls.forte
|
||||||
cls.currency = cls.currency_usd
|
cls.currency = cls.currency_usd
|
||||||
cls.forte = cls.acquirer
|
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 = cls.env['account.journal'].search([], limit=1)[0]
|
||||||
cls.journal.write({
|
cls.journal.write({
|
||||||
'inbound_payment_method_line_ids': [(0, 0, {
|
'inbound_payment_method_line_ids': [(0, 0, {
|
||||||
@@ -65,6 +63,8 @@ class ForteACH(ForteCommon):
|
|||||||
'payment_method_line_id': self.method_line.id,
|
'payment_method_line_id': self.method_line.id,
|
||||||
'amount': 22.00,
|
'amount': 22.00,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
payment.action_post()
|
||||||
self.assertTrue(payment.payment_transaction_id)
|
self.assertTrue(payment.payment_transaction_id)
|
||||||
self.assertEqual(payment.payment_transaction_id.amount, 22.00)
|
self.assertEqual(payment.payment_transaction_id.amount, 22.00)
|
||||||
self.assertTrue(payment.payment_transaction_id.acquirer_reference)
|
self.assertTrue(payment.payment_transaction_id.acquirer_reference)
|
||||||
|
|||||||
Reference in New Issue
Block a user