[IMP] payment, website_sale: better control of sale order confirmation in ecommerce.
authorThibault Delavallée <tde@openerp.com>
Thu, 9 Oct 2014 09:13:30 +0000 (11:13 +0200)
committerThibault Delavallée <tde@openerp.com>
Thu, 9 Oct 2014 10:50:13 +0000 (12:50 +0200)
Auto confirmation is now controlled by a field on the acquirer
that proposes to confirm
- at payment (Pay Now button on ecommerce)
- at payment confirmation (transaction feedback)
- never

Also fixed the state of tx for transfer transactions that was modified
for debugging in a previous task but not reverted.

addons/payment/models/payment_acquirer.py
addons/payment_transfer/models/payment_acquirer.py
addons/website_sale/controllers/main.py
addons/website_sale/models/payment.py

index d060c8f..37a1c4c 100644 (file)
@@ -75,6 +75,11 @@ class PaymentAcquirer(osv.Model):
         'website_published': fields.boolean(
             'Visible in Portal / Website', copy=False,
             help="Make this payment acquirer available (Customer invoices, etc.)"),
+        'auto_confirm': fields.selection(
+            [('none', 'No automatic confirmation'),
+             ('at_pay_confirm', 'At payment confirmation'),
+             ('at_pay_now', 'At payment')],
+            string='Auto Confirmation', required=True),
         # Fees
         'fees_active': fields.boolean('Compute fees'),
         'fees_dom_fixed': fields.float('Fixed domestic fees'),
@@ -88,6 +93,7 @@ class PaymentAcquirer(osv.Model):
         'environment': 'test',
         'validation': 'automatic',
         'website_published': True,
+        'auto_confirm': 'at_pay_confirm',
     }
 
     def _check_required_if_provider(self, cr, uid, ids, context=None):
index 8b8dc7a..63883b3 100644 (file)
@@ -83,4 +83,4 @@ class TransferPaymentTransaction(osv.Model):
 
     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': 'done'})
+        return tx.write({'state': 'pending'})
index d5fcfbb..f7f6c02 100644 (file)
@@ -676,6 +676,7 @@ class website_sale(http.Controller):
                 'sale_order_id': order.id,
             }, context=context)
             request.session['sale_transaction_id'] = tx_id
+            tx = transaction_obj.browse(cr, SUPERUSER_ID, tx_id, context=context)
 
         # update quotation
         request.registry['sale.order'].write(
@@ -684,6 +685,10 @@ class website_sale(http.Controller):
                 'payment_tx_id': request.session['sale_transaction_id']
             }, context=context)
 
+        # confirm the quotation
+        if tx.acquirer_id.auto_confirm == 'at_pay_now':
+            request.registry['sale.order'].action_button_confirm(cr, SUPERUSER_ID, [order.id], context=request.context)
+
         return tx_id
 
     @http.route('/shop/payment/get_status/<int:sale_order_id>', type='json', auth="public", website=True)
index 36b681a..6ab7e97 100644 (file)
@@ -22,7 +22,7 @@ class PaymentTransaction(orm.Model):
         tx_find_method_name = '_%s_form_get_tx_from_data' % acquirer_name
         if hasattr(self, tx_find_method_name):
             tx = getattr(self, tx_find_method_name)(cr, uid, data, context=context)
-        if tx and tx.state == 'done' and tx.sale_order_id and tx.sale_order_id.state in ['draft', 'sent']:
+        if tx and tx.state == 'done' and tx.auto_confirm == 'at_pay_confirm' and tx.sale_order_id and tx.sale_order_id.state in ['draft', 'sent']:
             self.pool['sale.order'].action_button_confirm(cr, SUPERUSER_ID, [tx.sale_order_id.id], context=context)
 
         return res