From 5dcb10fc0140a9d0e321c17688d4171a12f3282b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 20 Nov 2013 15:03:21 +0100 Subject: [PATCH] [IMP] website_sale: end of checkout process improvements - added a controller that validates the payment: confirm the quotation (if paid) and send it by email - some fixes in payment routes - some cleaning in payment template, removed unnecessary code, added a class on a div to ease the submit button management bzr revid: tde@openerp.com-20131120140321-mderltwy8xp2vfn4 --- addons/website_sale/controllers/main.py | 44 ++++++++++++++++--- .../static/src/js/website_sale_payment.js | 4 +- .../static/src/js/website_sale_validate.js | 19 +++++--- addons/website_sale/views/website_sale.xml | 12 ++--- 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 3e1aef964e8..1d520bc5589 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -686,7 +686,8 @@ class Ecommerce(http.Controller): return request.website.render("website_sale.payment", values) - @website.route(['/shop/payment/transaction//'], type='http', auth="public") + @website.route(['/shop/payment/transaction/'], + type='http', methods=['POST'], auth="public") def payment_transaction(self, acquirer_id=None, **post): """ Hook method that creates a payment.transaction and redirect to the acquirer, using post values to re-create the post action. @@ -703,7 +704,7 @@ class Ecommerce(http.Controller): transaction_obj = request.registry.get('payment.transaction') order = request.registry['website'].get_current_order(request.cr, request.uid, context=request.context) - if not order or not order.order_line or not acquirer_id: + if not order or not order.order_line or acquirer_id is None: return request.redirect("/shop/checkout/") # find an already existing transaction @@ -727,21 +728,50 @@ class Ecommerce(http.Controller): acquirer_total_url = '%s?%s' % (acquirer_form_post_url, urllib.urlencode(post)) return request.redirect(acquirer_total_url) - @website.route([ - '/shop/payment/transaction/get_status', - '/shop/payment/transaction/get_status/' - ], type='json', auth="public", multilang=True) - def payment_validation(self, transaction_id=None, **post): + @website.route('/shop/payment/confirm', type='json', auth="public", multilang=True) + def payment_confirm(self, transaction_id=None, **post): cr, uid, context = request.cr, request.uid, request.context payment_obj = request.registry.get('payment.transaction') if transaction_id: tx = payment_obj.browse(cr, uid, transaction_id, context=context) else: tx = context.get('website_sale_transaction') + return { 'state': tx.state, } + @website.route('/shop/payment/validate', type='json', auth="public", multilang=True) + def payment_validate(self): + cr, uid, context = request.cr, request.uid, request.context + email_act = None + sale_order_obj = request.registry['sale.order'] + + order = context.get('website_sale_order') + tx = context.get('website_sale_transaction') + + if not order or not tx: + return request.redirect("/shop/checkout/") + + if tx.state == 'done': + # confirm the quotation + sale_order_obj.action_button_confirm(cr, SUPERUSER_ID, [order.id], context=request.context) + # send by email + email_act = sale_order_obj.action_quotation_send(cr, SUPERUSER_ID, [order.id], context=request.context) + elif tx.state == 'pending': + # send by email + email_act = sale_order_obj.action_quotation_send(cr, SUPERUSER_ID, [order.id], context=request.context) + elif tx.state == 'cancel': + # cancel the quotation + sale_order_obj.action_cancel(cr, SUPERUSER_ID, [order.id], context=request.context) + + if email_act: + create_ctx = email_act.get('context', context) + compose_id = request.registry['mail.compose.message'].create(cr, uid, {}, context=create_ctx) + request.registry['mail.compose.message'].send_mail(cr, uid, [compose_id], context=create_ctx) + + return True + @website.route(['/shop/confirmation/'], type='http', auth="public", multilang=True) def payment_confirmation(self, **post): context = request.context 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 facf25610a3..3da753c03f9 100644 --- a/addons/website_sale/static/src/js/website_sale_payment.js +++ b/addons/website_sale/static/src/js/website_sale_payment.js @@ -6,9 +6,9 @@ $(document).ready(function () { * query. */ $('input#payment_submit').on('click', function (ev) { // TDEFIXME: change input#ID to input inside payment form, less strict - var acquirer_id = $(this).closest('form').closest('div').data().id || 0; + var acquirer_id = $(this).closest('form').closest('div.oe_payment_acquirer').data().id || 0; var form_action = $(this).closest("form").attr('action'); console.log('cliking on submit for payment - redirecting from', form_action, 'to shop with acqurier_id', acquirer_id); - $(this).closest("form").attr("action", '/shop/payment/transaction/' + acquirer_id + '/'); + $(this).closest("form").attr("action", '/shop/payment/transaction/' + acquirer_id); }); }); diff --git a/addons/website_sale/static/src/js/website_sale_validate.js b/addons/website_sale/static/src/js/website_sale_validate.js index 681fd50411b..8e38f5e6306 100644 --- a/addons/website_sale/static/src/js/website_sale_validate.js +++ b/addons/website_sale/static/src/js/website_sale_validate.js @@ -2,9 +2,14 @@ $(document).ready(function () { var _poll_nbr = 0; + function payment_transaction_validate() { + return openerp.jsonRpc('/shop/payment/validate', 'call', {}); + } + function payment_transaction_poll_status() { - return openerp.jsonRpc('/shop/payment/transaction/get_status', 'call', { - }).then(function (result) { + return openerp.jsonRpc('/shop/payment/confirm', 'call', { + }).done(function (result) { + // console.log('--done', result); _poll_nbr += 1; if (result.state == 'done') { $('div.oe_website_sale_confirmation').html(function() { @@ -12,13 +17,14 @@ $(document).ready(function () { }); } else if (result.state == 'pending') { - if (_poll_nbr <= 10) { + if (_poll_nbr <= 2) { $('div.oe_website_sale_confirmation').html(function() { return "

Waiting validation ...

"; }); setTimeout(function () { - return payment_transaction_poll_status(); + return inner_done = payment_transaction_poll_status(); }, 1000); + // return inner_done; } else { $('div.oe_website_sale_confirmation').html(function() { @@ -34,5 +40,8 @@ $(document).ready(function () { }); } - payment_transaction_poll_status(); + payment_transaction_poll_status().done(function (result) { + // console.log('finished', result); + payment_transaction_validate(); + }); }); diff --git a/addons/website_sale/views/website_sale.xml b/addons/website_sale/views/website_sale.xml index c5b46f4a700..8eea602d876 100644 --- a/addons/website_sale/views/website_sale.xml +++ b/addons/website_sale/views/website_sale.xml @@ -892,21 +892,15 @@
+ +
-