如何解决在odoo中确认订单后发送电子邮件
我创建了一个付款收款人,即COD(货到付款),
在网站商店中,当用户购买产品并选择付款方式COD时,它会创建销售订单并进行确认,但它不会向用户发送确认电子邮件,也不会像默认电汇一样在聊天记录中输入内容。电汇会发送一个默认的电子邮件模板,该模板是用户通过单击“通过电子邮件发送”按钮从报价中手动发送的模板。
我在犯错。
这是我的代码。
@http.route('/shop/payment/validate',type='http',auth="public",website=True,sitemap=False)
def payment_validate(self,transaction_id=None,sale_order_id=None,**post):
if sale_order_id is None:
order = request.website.sale_get_order()
else:
order = request.env['sale.order'].sudo().browse(sale_order_id)
assert order.id == request.session.get('sale_last_order_id')
if transaction_id:
tx = request.env['payment.transaction'].sudo().browse(transaction_id)
assert tx in order.transaction_ids()
elif order:
tx = order.get_portal_last_transaction()
else:
tx = None
if not order or (order.amount_total and not tx):
return request.redirect('/shop')
if (not order.amount_total and not tx) or tx.state in ['pending','done','authorized']:
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.with_context(send_email=True).action_confirm()
elif tx and tx.state == 'cancel':
# cancel the quotation
order.action_cancel()
# clean context and session,then redirect to the confirmation page
request.website.sale_reset()
if tx and tx.state == 'draft':
return request.redirect('/shop')
if tx.acquirer_id.provider == 'cod':
payment_acquirer_obj = request.env['payment.acquirer'].sudo().search([('id','=',tx.acquirer_id.id)])
product_obj = request.env['product.product']
extra_fees_product = request.env['ir.model.data'].get_object_reference('bi_website_cash_on_delivery','product_product_fees')[1]
product_ids = product_obj.sudo().search([('product_tmpl_id.id',extra_fees_product)])
order_line_obj = request.env['sale.order.line'].sudo().search([])
flag = 0
for i in order_line_obj:
if i.product_id.id == product_ids.id and i.order_id.id == order.id:
flag = flag + 1
if flag == 0:
order_line_obj.sudo().create({
'product_id': product_ids.id,'name': 'Extra Fees','price_unit': payment_acquirer_obj.delivery_fees,'order_id': order.id,'product_uom':product_ids.uom_id.id,})
tx.update({
'fees' : payment_acquirer_obj.delivery_fees
})
order.with_context(send_email=True).action_confirm()
request.website.sale_reset()
PaymentProcessing.remove_payment_transaction(tx)
return request.redirect('/shop/confirmation')
解决方法
好的,所以我得到了自己的问题的解决方法。
在控制器中,我在request.website.sale_reset()
之前编写了此代码,并删除了order.with_context(send_email=True).action_confirm()
。
order.action_confirm()
email_act = order.action_quotation_send()
email_ctx = email_act.get('context',{})
order.with_context(**email_ctx).message_post_with_template(email_ctx.get('default_template_id'))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。