diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 43ec6998b28..1074060c07e 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -1,6 +1,7 @@ # -*- coding: utf-'8' "-*-" import logging +import openerp from openerp.osv import osv, fields from openerp.tools import float_round, float_repr from openerp.tools.translate import _ @@ -499,6 +500,14 @@ class PaymentTransaction(osv.Model): 'partner_phone': partner and partner.phone or False, }} + def get_next_reference(self, cr, uid, reference, context=None): + ref_suffix = 1 + init_ref = reference + while self.pool['payment.transaction'].search_count(cr, openerp.SUPERUSER_ID, [('reference', '=', reference)], context=context): + reference = init_ref + '-' + str(ref_suffix) + ref_suffix += 1 + return reference + # -------------------------------------------------- # FORM RELATED METHODS # -------------------------------------------------- diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index c7fa5e96b99..d44446071a5 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -704,10 +704,6 @@ class website_sale(http.Controller): values['errors'] = sale_order_obj._get_errors(cr, uid, order, context=context) values.update(sale_order_obj._get_website_data(cr, uid, order, context)) - # fetch all registered payment means - # if tx: - # acquirer_ids = [tx.acquirer_id.id] - # else: if not values['errors']: acquirer_ids = payment_obj.search(cr, SUPERUSER_ID, [('website_published', '=', True), ('company_id', '=', order.company_id.id)], context=context) values['acquirers'] = list(payment_obj.browse(cr, uid, acquirer_ids, context=context)) @@ -715,7 +711,7 @@ class website_sale(http.Controller): for acquirer in values['acquirers']: acquirer.button = payment_obj.render( cr, SUPERUSER_ID, acquirer.id, - order.name, + '/', order.amount_total, order.pricelist_id.currency_id.id, partner_id=shipping_partner_id, @@ -737,6 +733,7 @@ class website_sale(http.Controller): user is redirected to the checkout page """ cr, uid, context = request.cr, request.uid, request.context + payment_obj = request.registry.get('payment.acquirer') transaction_obj = request.registry.get('payment.transaction') order = request.website.sale_get_order(context=context) @@ -749,14 +746,11 @@ class website_sale(http.Controller): tx = request.website.sale_get_transaction() if tx: tx_id = tx.id - if tx.reference != order.name: + if tx.sale_order_id.id != order.id or tx.state in ['error', 'cancel'] or tx.acquirer_id.id != acquirer_id: tx = False tx_id = False elif tx.state == 'draft': # button cliked but no more info -> rewrite on tx or create a new one ? - tx.write({ - 'acquirer_id': acquirer_id, - 'amount': order.amount_total, - }) + tx.write(dict(transaction_obj.on_change_partner_id(cr, uid, None, order.partner_id.id, context=context).get('values', {}), amount=order.amount_total)) if not tx: tx_id = transaction_obj.create(cr, SUPERUSER_ID, { 'acquirer_id': acquirer_id, @@ -765,7 +759,7 @@ class website_sale(http.Controller): 'currency_id': order.pricelist_id.currency_id.id, 'partner_id': order.partner_id.id, 'partner_country_id': order.partner_id.country_id.id, - 'reference': order.name, + 'reference': request.env['payment.transaction'].get_next_reference(order.name), 'sale_order_id': order.id, }, context=context) request.session['sale_transaction_id'] = tx_id @@ -782,7 +776,16 @@ class website_sale(http.Controller): if tx.acquirer_id.auto_confirm == 'at_pay_now': request.registry['sale.order'].action_button_confirm(cr, SUPERUSER_ID, [order.id], context=dict(request.context, send_email=True)) - return tx_id + return payment_obj.render( + cr, SUPERUSER_ID, tx.acquirer_id.id, + tx.reference, + order.amount_total, + order.pricelist_id.currency_id.id, + partner_id=order.partner_shipping_id.id or order.partner_invoice_id.id, + tx_values={ + 'return_url': '/shop/payment/validate', + }, + context=dict(context, submit_class='btn btn-primary', submit_txt=_('Pay Now'))) @http.route('/shop/payment/get_status/', type='json', auth="public", website=True) def payment_get_status(self, sale_order_id, **post): diff --git a/addons/website_sale/static/src/js/website_sale_payment.js b/addons/website_sale/static/src/js/website_sale_payment.js index 8ca1b85f907..94ebde001b2 100644 --- a/addons/website_sale/static/src/js/website_sale_payment.js +++ b/addons/website_sale/static/src/js/website_sale_payment.js @@ -19,6 +19,7 @@ $(document).ready(function () { return false; } openerp.jsonRpc('/shop/payment/transaction/' + acquirer_id, 'call', {}).then(function (data) { + $form.html(data); $form.submit(); }); });