[IMP] website_sale: confirm quotation only when the payment is done, not directly when hitting 'pay now'.

This commit is contained in:
Thibault Delavallée 2014-09-03 13:21:23 +02:00
parent 428cb3fb13
commit dce983dea0
4 changed files with 30 additions and 12 deletions

View File

@ -646,7 +646,6 @@ class website_sale(http.Controller):
"""
cr, uid, context = request.cr, request.uid, request.context
transaction_obj = request.registry.get('payment.transaction')
sale_order_obj = request.registry['sale.order']
order = request.website.sale_get_order(context=context)
if not order or not order.order_line or acquirer_id is None:
@ -676,13 +675,11 @@ class website_sale(http.Controller):
request.session['sale_transaction_id'] = tx_id
# update quotation
sale_order_obj.write(
request.registry['sale.order'].write(
cr, SUPERUSER_ID, [order.id], {
'payment_acquirer_id': acquirer_id,
'payment_tx_id': request.session['sale_transaction_id']
}, context=context)
# confirm the quotation
sale_order_obj.action_button_confirm(cr, SUPERUSER_ID, [order.id], context=request.context)
return tx_id

View File

@ -1,2 +1,3 @@
import product
import sale_order
import payment

View File

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from openerp import SUPERUSER_ID
from openerp.osv import orm, fields
class PaymentTransaction(orm.Model):
_inherit = 'payment.transaction'
_columns = {
# link with the sale order
'sale_order_id': fields.many2one('sale.order', 'Sale Order'),
}
def form_feedback(self, cr, uid, data, acquirer_name, context=None):
""" Override to confirm the sale order, if defined, and if the transaction
is done. """
tx = None
res = super(PaymentTransaction, self).form_feedback(cr, uid, data, acquirer_name, context=context)
# fetch the tx, check its state, confirm the potential SO
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']:
self.pool['sale.order'].action_button_confirm(cr, SUPERUSER_ID, [tx.sale_order_id.id], context=context)
return res

View File

@ -6,14 +6,6 @@ from openerp.osv import osv, orm, fields
from openerp.addons.web.http import request
class payment_transaction(orm.Model):
_inherit = 'payment.transaction'
_columns = {
# link with the sale order
'sale_order_id': fields.many2one('sale.order', 'Sale Order'),
}
class sale_order(osv.Model):
_inherit = "sale.order"