[FIX] sale, website_sale: Send email on sale order confirmation
Not just when coming back from the payment provider to the payment validation route `/shop/payment/validate`. Otherwise, if you do not come back from the payment provider page, that you quit just after having paid but just before being redirected to Odoo, you do not receive the email. The change within the `sale` module, while this issue concerns `website_sale` only, has been accepted because this is a mechanism that could be used by other modules. opw-644348
This commit is contained in:
parent
85a06f8a6e
commit
4adb4b8d15
|
@ -598,8 +598,31 @@ class sale_order(osv.osv):
|
|||
return True
|
||||
|
||||
def action_button_confirm(self, cr, uid, ids, context=None):
|
||||
if not context:
|
||||
context = {}
|
||||
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)
|
||||
return True
|
||||
|
||||
def action_wait(self, cr, uid, ids, context=None):
|
||||
|
|
|
@ -802,33 +802,11 @@ class website_sale(http.Controller):
|
|||
if (not order.amount_total and not tx):
|
||||
# Orders are confirmed by payment transactions, but there is none for free orders,
|
||||
# (e.g. free events), so confirm immediately
|
||||
order.action_button_confirm()
|
||||
# send by email
|
||||
email_act = sale_order_obj.action_quotation_send(cr, SUPERUSER_ID, [order.id], context=request.context)
|
||||
order.with_context(dict(context, send_email=True)).action_button_confirm()
|
||||
elif tx and tx.state == 'cancel':
|
||||
# cancel the quotation
|
||||
sale_order_obj.action_cancel(cr, SUPERUSER_ID, [order.id], context=request.context)
|
||||
|
||||
# send the email
|
||||
if email_act and email_act.get('context'):
|
||||
composer_obj = request.registry['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, SUPERUSER_ID, None, *template_values, context=context).get('value', {}))
|
||||
if not composer_values.get('email_from') and uid == request.website.user_id.id:
|
||||
composer_values['email_from'] = request.website.user_id.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, SUPERUSER_ID, composer_values, context=email_ctx)
|
||||
composer_obj.send_mail(cr, SUPERUSER_ID, [composer_id], context=email_ctx)
|
||||
|
||||
# clean context and session, then redirect to the confirmation page
|
||||
request.website.sale_reset(context=context)
|
||||
|
||||
|
|
|
@ -23,6 +23,6 @@ class PaymentTransaction(orm.Model):
|
|||
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)
|
||||
self.pool['sale.order'].action_button_confirm(cr, SUPERUSER_ID, [tx.sale_order_id.id], context=dict(context, send_email=True))
|
||||
|
||||
return res
|
||||
|
|
Loading…
Reference in New Issue