diff options
| author | Atul Patel (OpenERP) <atp@tinyerp.com> | 2014-02-18 11:26:18 +0530 |
|---|---|---|
| committer | Atul Patel (OpenERP) <atp@tinyerp.com> | 2014-02-18 11:26:18 +0530 |
| commit | 33b99c8a0737e08e6a243e41bb455d3ab7e6c851 (patch) | |
| tree | a1db52bfbeecf0c6fd9096604b7ec4540bb04197 /addons/payment_transfer | |
| parent | caa3510ea434e10c32dcbc134f9c74b2b9f18b2a (diff) | |
| parent | aa0eac1257b97c1be693e8a804fec6ecbf2bb22f (diff) | |
[MERGE]: Merged with addons
bzr revid: atp@tinyerp.com-20140218055618-r36w29vat7zig9ar
Diffstat (limited to 'addons/payment_transfer')
| -rw-r--r-- | addons/payment_transfer/__init__.py | 23 | ||||
| -rw-r--r-- | addons/payment_transfer/__openerp__.py | 17 | ||||
| -rw-r--r-- | addons/payment_transfer/controllers/__init__.py | 3 | ||||
| -rw-r--r-- | addons/payment_transfer/controllers/main.py | 22 | ||||
| -rw-r--r-- | addons/payment_transfer/data/transfer.xml | 18 | ||||
| -rw-r--r-- | addons/payment_transfer/models/__init__.py | 3 | ||||
| -rw-r--r-- | addons/payment_transfer/models/payment_acquirer.py | 81 | ||||
| -rw-r--r-- | addons/payment_transfer/static/description/icon.png | bin | 0 -> 13148 bytes | |||
| -rw-r--r-- | addons/payment_transfer/static/src/img/transfer_icon.png | bin | 0 -> 14605 bytes | |||
| -rw-r--r-- | addons/payment_transfer/views/transfer.xml | 23 |
10 files changed, 190 insertions, 0 deletions
diff --git a/addons/payment_transfer/__init__.py b/addons/payment_transfer/__init__.py new file mode 100644 index 00000000000..dde6f25c728 --- /dev/null +++ b/addons/payment_transfer/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +import models +import controllers diff --git a/addons/payment_transfer/__openerp__.py b/addons/payment_transfer/__openerp__.py new file mode 100644 index 00000000000..f8c36b4f365 --- /dev/null +++ b/addons/payment_transfer/__openerp__.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +{ + 'name': 'Transfer Payment Acquirer', + 'category': 'Hidden', + 'summary': 'Payment Acquirer: Transfer Implementation', + 'version': '1.0', + 'description': """Transfer Payment Acquirer""", + 'author': 'OpenERP SA', + 'depends': ['payment'], + 'data': [ + 'views/transfer.xml', + 'data/transfer.xml', + ], + 'installable': True, + 'auto_install': True, +} diff --git a/addons/payment_transfer/controllers/__init__.py b/addons/payment_transfer/controllers/__init__.py new file mode 100644 index 00000000000..bbd183e955b --- /dev/null +++ b/addons/payment_transfer/controllers/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +import main diff --git a/addons/payment_transfer/controllers/main.py b/addons/payment_transfer/controllers/main.py new file mode 100644 index 00000000000..917ac63cc81 --- /dev/null +++ b/addons/payment_transfer/controllers/main.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +import logging +import pprint +import werkzeug + +from openerp import http, SUPERUSER_ID +from openerp.http import request + +_logger = logging.getLogger(__name__) + + +class OgoneController(http.Controller): + _accept_url = '/payment/transfer/feedback' + + @http.route([ + '/payment/transfer/feedback', + ], type='http', auth='none') + def transfer_form_feedback(self, **post): + cr, uid, context = request.cr, SUPERUSER_ID, request.context + _logger.info('Beginning form_feedback with post data %s', pprint.pformat(post)) # debug + request.registry['payment.transaction'].form_feedback(cr, uid, post, 'transfer', context) + return werkzeug.utils.redirect(post.pop('return_url', '/')) diff --git a/addons/payment_transfer/data/transfer.xml b/addons/payment_transfer/data/transfer.xml new file mode 100644 index 00000000000..c2863971d34 --- /dev/null +++ b/addons/payment_transfer/data/transfer.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data noupdate="1"> + + <record id="payment_acquirer_transfer" model="payment.acquirer"> + <field name="name">transfer</field> + <field name="company_id" ref="base.main_company"/> + <field name="view_template_id" ref="transfer_acquirer_button"/> + <field name="validation">manual</field> + <field name="env">test</field> + <field name="website_published" eval="True"/> + <field name="pre_msg"><![CDATA[ +<p>Transfer information will be provided after choosing the payment mode.</p>]]> + </field> + </record> + + </data> +</openerp> diff --git a/addons/payment_transfer/models/__init__.py b/addons/payment_transfer/models/__init__.py new file mode 100644 index 00000000000..da51c9c1854 --- /dev/null +++ b/addons/payment_transfer/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +import payment_acquirer diff --git a/addons/payment_transfer/models/payment_acquirer.py b/addons/payment_transfer/models/payment_acquirer.py new file mode 100644 index 00000000000..90b1329ff25 --- /dev/null +++ b/addons/payment_transfer/models/payment_acquirer.py @@ -0,0 +1,81 @@ +# -*- coding: utf-'8' "-*-" + +from openerp.addons.payment.models.payment_acquirer import ValidationError +from openerp.osv import osv +from openerp.tools.float_utils import float_compare +from openerp.tools.translate import _ + +import logging +import pprint + +_logger = logging.getLogger(__name__) + + +class TransferPaymentAcquirer(osv.Model): + _inherit = 'payment.acquirer' + + def transfer_get_form_action_url(self, cr, uid, id, context=None): + return '/payment/transfer/feedback' + + def _format_transfer_data(self, cr, uid, context=None): + bank_ids = [bank.id for bank in self.pool['res.users'].browse(cr, uid, uid, context=context).company_id.bank_ids] + # filter only bank accounts marked as visible + bank_ids = self.pool['res.partner.bank'].search(cr, uid, [('id', 'in', bank_ids), ('footer', '=', True)], context=context) + accounts = self.pool['res.partner.bank'].name_get(cr, uid, bank_ids, context=context) + 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 + + def create(self, cr, uid, values, context=None): + """ 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('name') == 'transfer' and not values.get('post_msg'): + values['post_msg'] = self._format_transfer_data(cr, uid, context=context) + return super(TransferPaymentAcquirer, self).create(cr, uid, values, context=context) + + +class TransferPaymentTransaction(osv.Model): + _inherit = 'payment.transaction' + + 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): + _logger.info('Validated transfer payment for tx %s: set as pending' % (tx.reference)) + return tx.write({'state': 'pending'}) diff --git a/addons/payment_transfer/static/description/icon.png b/addons/payment_transfer/static/description/icon.png Binary files differnew file mode 100644 index 00000000000..183937ed9ce --- /dev/null +++ b/addons/payment_transfer/static/description/icon.png diff --git a/addons/payment_transfer/static/src/img/transfer_icon.png b/addons/payment_transfer/static/src/img/transfer_icon.png Binary files differnew file mode 100644 index 00000000000..63b10e383ec --- /dev/null +++ b/addons/payment_transfer/static/src/img/transfer_icon.png diff --git a/addons/payment_transfer/views/transfer.xml b/addons/payment_transfer/views/transfer.xml new file mode 100644 index 00000000000..ddb45d32e8d --- /dev/null +++ b/addons/payment_transfer/views/transfer.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data noupdate="1"> + + <template id="transfer_acquirer_button"> + <form t-if="acquirer" t-att-action="tx_url" method="post" target="_self"> + <t t-if="tx_values.get('return_url')"> + <input type='hidden' name='return_url' t-att-value='tx_values["return_url"]'/> + </t> + <input type='hidden' name='reference' t-att-value='reference'/> + <input type='hidden' name='amount' t-att-value='amount or "0.0"'/> + <input type='hidden' name='currency' t-att-value='currency.name'/> + <!-- submit --> + <button name="submit" width="100px" + t-att-class="submit_class"> + <img t-if="not submit_txt" src="/payment_transfer/static/src/img/transfer_icon.png"/> + <span t-if="submit_txt"><t t-esc="submit_txt"/> <span class="fa fa-long-arrow-right"/></span> + </button> + </form> + </template> + + </data> +</openerp> |
