2013-11-08 09:44:44 +00:00
|
|
|
# -*- coding: utf-'8' "-*-"
|
|
|
|
|
2014-01-22 17:57:02 +00:00
|
|
|
from openerp.addons.payment.models.payment_acquirer import ValidationError
|
2013-11-08 09:44:44 +00:00
|
|
|
from openerp.osv import osv
|
2013-11-20 14:01:19 +00:00
|
|
|
from openerp.tools.float_utils import float_compare
|
2013-11-08 09:44:44 +00:00
|
|
|
|
|
|
|
import logging
|
2013-11-20 14:01:19 +00:00
|
|
|
import pprint
|
2013-11-08 09:44:44 +00:00
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class TransferPaymentAcquirer(osv.Model):
|
2013-11-08 10:10:05 +00:00
|
|
|
_inherit = 'payment.acquirer'
|
2013-11-08 09:44:44 +00:00
|
|
|
|
2013-11-20 14:01:19 +00:00
|
|
|
def transfer_get_form_action_url(self, cr, uid, id, context=None):
|
|
|
|
return '/payment/transfer/feedback'
|
|
|
|
|
2013-11-08 09:44:44 +00:00
|
|
|
|
|
|
|
class TransferPaymentTransaction(osv.Model):
|
2013-11-08 10:10:05 +00:00
|
|
|
_inherit = 'payment.transaction'
|
2013-11-19 18:04:00 +00:00
|
|
|
|
2013-11-20 14:01:19 +00:00
|
|
|
def _transfer_form_get_tx_from_data(self, cr, uid, data, context=None):
|
|
|
|
reference, amount, currency_name = data.get('reference'), data.get('amount'), data.get('currency_name')
|
|
|
|
tx_ids = self.search(
|
|
|
|
cr, uid, [
|
|
|
|
('reference', '=', reference),
|
|
|
|
], context=context)
|
|
|
|
|
|
|
|
if not tx_ids or len(tx_ids) > 1:
|
|
|
|
error_msg = 'received data for reference %s' % (pprint.pformat(reference))
|
|
|
|
if not tx_ids:
|
|
|
|
error_msg += '; no order found'
|
|
|
|
else:
|
|
|
|
error_msg += '; multiple order found'
|
|
|
|
_logger.error(error_msg)
|
|
|
|
raise ValidationError(error_msg)
|
|
|
|
|
|
|
|
return self.browse(cr, uid, tx_ids[0], context=context)
|
|
|
|
|
|
|
|
def _transfer_form_get_invalid_parameters(self, cr, uid, tx, data, context=None):
|
|
|
|
invalid_parameters = []
|
|
|
|
|
|
|
|
if float_compare(float(data.get('amount', '0.0')), tx.amount, 2) != 0:
|
|
|
|
invalid_parameters.append(('amount', data.get('amount'), '%.2f' % tx.amount))
|
|
|
|
if data.get('currency') != tx.currency_id.name:
|
|
|
|
invalid_parameters.append(('currency', data.get('currency'), tx.currency_id.name))
|
|
|
|
|
|
|
|
return invalid_parameters
|
|
|
|
|
|
|
|
def _transfer_form_validate(self, cr, uid, tx, data, context=None):
|
2013-11-21 12:07:45 +00:00
|
|
|
_logger.info('Validated transfer payment for tx %s: set as pending' % (tx.reference))
|
2013-11-20 14:01:19 +00:00
|
|
|
return tx.write({'state': 'pending'})
|