Files
odoo_source/addons/payment_transfer/models/payment.py
T
qdp-odoo 01216345e2 [REF] account,payment(_*),sale*: downgrade transactions into debug items
It was very confusing for the user to distinct account.payment and payment.transaction. From now on, the transactions are
technical objects and, in the backend, we only refer to it in log messages (Front end will be adapted in the same fashion
later on). They are hidden in debug mode in accounting\configuration\payments as their purpose is now purely technical/log

This commit also aims to reduce the gap between the accounting app and the transactions: account.payment objects are
created/validated upon completion of transaction.

To ease the capture/voiding of pending transactions, the related buttons are now displayed directly on the SO/invoice
instead of the transactions.

Was task: https://www.odoo.com/web#id=35857&view_type=form&model=project.task&action=333&active_id=967&menu_id=4720
Was PR #24043

[FIX] add domain based on journal to payment tokens

Was opw: https://www.odoo.com/web?debug#id=1828206&view_type=form&model=project.task&menu_id=5200
2018-05-23 15:44:55 +02:00

103 lines
4.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')
@api.model
def _create_missing_journal_for_acquirers(self):
# By default, the wire transfer method uses the default Bank journal.
company = self.env.user.company_id
acquirers = self.env['payment.acquirer'].search(
[('provider', '=', 'transfer'), ('journal_id', '=', False), ('company_id', '=', company.id)])
bank_journal = self.env['account.journal'].search(
[('type', '=', 'bank'), ('company_id', '=', company.id)], limit=1)
if bank_journal:
acquirers.write({'journal_id': bank_journal.id})
return super(TransferPaymentAcquirer, self)._create_missing_journal_for_acquirers()
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'), ('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)
@api.multi
def write(self, values):
""" Hook in write to create a default post_msg. See create(). """
if all(not acquirer.post_msg and acquirer.provider != 'transfer' for acquirer in self) and values.get('provider') == 'transfer':
values['post_msg'] = self._format_transfer_data()
return super(TransferPaymentAcquirer, self).write(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))
self._set_transaction_pending()
return True