From 809e1a60813e0468ffc3f52f866119bb8cfe3a58 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Tue, 14 Jul 2015 11:01:28 +0200 Subject: [PATCH] [FIX] sale, website_sale: quotation email. 4adb4b8d15c528f8946cc8c766fa712c3effbb85 corrected the fact the quotation email wasn't sent if you did not come back from the payment provider (when you closed your browser after the payment but before coming back to Odoo). Before the above revision, the quotation email was sent for payment methods not redirecting to payment providers, like transfers. It was no longer the case with the above revision. This revision re-introduces this behavior: If there is a feedback from a transaction, but the transaction isn't confirmed, we send the quotation email without confirming the sale order, like it was the case before opw-644670 --- addons/sale/sale.py | 44 +++++++++++++++------------ addons/website_sale/models/payment.py | 2 ++ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 0575c48d2bd..2e628088600 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -603,26 +603,7 @@ class sale_order(osv.osv): assert len(ids) == 1, 'This option should only be used for a single id at a time.' self.signal_workflow(cr, uid, ids, 'order_confirm') if context.get('send_email'): - order_id = ids[0] - email_act = self.action_quotation_send(cr, uid, [order_id], context=context) - if email_act and email_act.get('context'): - composer_obj = self.pool['mail.compose.message'] - composer_values = {} - email_ctx = email_act['context'] - template_values = [ - email_ctx.get('default_template_id'), - email_ctx.get('default_composition_mode'), - email_ctx.get('default_model'), - email_ctx.get('default_res_id'), - ] - composer_values.update(composer_obj.onchange_template_id(cr, uid, None, *template_values, context=context).get('value', {})) - if not composer_values.get('email_from'): - composer_values['email_from'] = self.browse(cr, uid, order_id, context=context).company_id.email - for key in ['attachment_ids', 'partner_ids']: - if composer_values.get(key): - composer_values[key] = [(6, 0, composer_values[key])] - composer_id = composer_obj.create(cr, uid, composer_values, context=email_ctx) - composer_obj.send_mail(cr, uid, [composer_id], context=email_ctx) + self.force_quotation_send(cr, uid, ids, context=context) return True def action_wait(self, cr, uid, ids, context=None): @@ -672,6 +653,29 @@ class sale_order(osv.osv): 'context': ctx, } + def force_quotation_send(self, cr, uid, ids, context=None): + for order_id in ids: + email_act = self.action_quotation_send(cr, uid, [order_id], context=context) + if email_act and email_act.get('context'): + composer_obj = self.pool['mail.compose.message'] + composer_values = {} + email_ctx = email_act['context'] + template_values = [ + email_ctx.get('default_template_id'), + email_ctx.get('default_composition_mode'), + email_ctx.get('default_model'), + email_ctx.get('default_res_id'), + ] + composer_values.update(composer_obj.onchange_template_id(cr, uid, None, *template_values, context=context).get('value', {})) + if not composer_values.get('email_from'): + composer_values['email_from'] = self.browse(cr, uid, order_id, context=context).company_id.email + for key in ['attachment_ids', 'partner_ids']: + if composer_values.get(key): + composer_values[key] = [(6, 0, composer_values[key])] + composer_id = composer_obj.create(cr, uid, composer_values, context=email_ctx) + composer_obj.send_mail(cr, uid, [composer_id], context=email_ctx) + return True + def action_done(self, cr, uid, ids, context=None): for order in self.browse(cr, uid, ids, context=context): self.pool.get('sale.order.line').write(cr, uid, [line.id for line in order.order_line if line.state != 'cancel'], {'state': 'done'}, context=context) diff --git a/addons/website_sale/models/payment.py b/addons/website_sale/models/payment.py index 32411b56c1e..a76bba4bca8 100644 --- a/addons/website_sale/models/payment.py +++ b/addons/website_sale/models/payment.py @@ -24,5 +24,7 @@ class PaymentTransaction(orm.Model): 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=dict(context, send_email=True)) + elif tx and tx.state not in ['cancel'] and tx.sale_order_id and tx.sale_order_id.state in ['draft']: + self.pool['sale.order'].force_quotation_send(cr, SUPERUSER_ID, [tx.sale_order_id.id], context=context) return res