- custom acquirer auto_confirm field changed to none.
- changed default_acquirer_button to actually display a button
used wire transfer's template (transfer_acquirer_button)
- set dependance to module_payment_transfer as it doesn't work without
and use transfer as provider.
Note: This is a quick fix to make it work, it's quite ugly.
Before the fix it didn't work an people duplicated the transfer
payment acquirer and edited it.
One downside for usability is that the payment icon will be the one
from transfer.
82 lines
3.2 KiB
Python
82 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo import api, fields, models, _
|
|
from odoo.addons.payment.models.payment_acquirer import ValidationError
|
|
from odoo.tools.float_utils import float_compare
|
|
|
|
import logging
|
|
import pprint
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class TransferPaymentAcquirer(models.Model):
|
|
_inherit = 'payment.acquirer'
|
|
|
|
provider = fields.Selection(selection_add=[('transfer', 'Wire Transfer')], default='transfer')
|
|
|
|
def transfer_get_form_action_url(self):
|
|
return '/payment/transfer/feedback'
|
|
|
|
def _format_transfer_data(self):
|
|
company_id = self.env.user.company_id.id
|
|
# filter only bank accounts marked as visible
|
|
journals = self.env['account.journal'].search([('type', '=', 'bank'), ('display_on_footer', '=', True), ('company_id', '=', company_id)])
|
|
accounts = journals.mapped('bank_account_id').name_get()
|
|
bank_title = _('Bank Accounts') if len(accounts) > 1 else _('Bank Account')
|
|
bank_accounts = ''.join(['<ul>'] + ['<li>%s</li>' % name for id, name in accounts] + ['</ul>'])
|
|
post_msg = '''<div>
|
|
<h3>Please use the following transfer details</h3>
|
|
<h4>%(bank_title)s</h4>
|
|
%(bank_accounts)s
|
|
<h4>Communication</h4>
|
|
<p>Please use the order name as communication reference.</p>
|
|
</div>''' % {
|
|
'bank_title': bank_title,
|
|
'bank_accounts': bank_accounts,
|
|
}
|
|
return post_msg
|
|
|
|
@api.model
|
|
def create(self, values):
|
|
""" Hook in create to create a default post_msg. This is done in create
|
|
to have access to the name and other creation values. If no post_msg
|
|
or a void post_msg is given at creation, generate a default one. """
|
|
if values.get('provider') == 'transfer' and not values.get('post_msg'):
|
|
values['post_msg'] = self._format_transfer_data()
|
|
return super(TransferPaymentAcquirer, self).create(values)
|
|
|
|
|
|
class TransferPaymentTransaction(models.Model):
|
|
_inherit = 'payment.transaction'
|
|
|
|
@api.model
|
|
def _transfer_form_get_tx_from_data(self, data):
|
|
reference, amount, currency_name = data.get('reference'), data.get('amount'), data.get('currency_name')
|
|
tx = self.search([('reference', '=', reference)])
|
|
|
|
if not tx or len(tx) > 1:
|
|
error_msg = _('received data for reference %s') % (pprint.pformat(reference))
|
|
if not tx:
|
|
error_msg += _('; no order found')
|
|
else:
|
|
error_msg += _('; multiple order found')
|
|
_logger.info(error_msg)
|
|
raise ValidationError(error_msg)
|
|
|
|
return tx
|
|
|
|
def _transfer_form_get_invalid_parameters(self, data):
|
|
invalid_parameters = []
|
|
|
|
if float_compare(float(data.get('amount', '0.0')), self.amount, 2) != 0:
|
|
invalid_parameters.append(('amount', data.get('amount'), '%.2f' % self.amount))
|
|
if data.get('currency') != self.currency_id.name:
|
|
invalid_parameters.append(('currency', data.get('currency'), self.currency_id.name))
|
|
|
|
return invalid_parameters
|
|
|
|
def _transfer_form_validate(self, data):
|
|
_logger.info('Validated transfer payment for tx %s: set as pending' % (self.reference))
|
|
return self.write({'state': 'pending'})
|