[IMP] payment, website_sale: better control of sale order confirmation in ecommerce.
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.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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'})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user