отправить электронное письмо, когда заказ будет подтвержден в odoo

Я создал платежную систему, то есть наложенным платежом (наложенным платежом),
в магазине веб-сайта, когда пользователь покупает продукт и выбирает способ оплаты, он создает заказ на продажу и подтверждает его, но не отправляет электронное письмо с подтверждением на пользователь или не помещает запись в чат, как это делает банковский перевод по умолчанию. банковский перевод отправляет шаблон электронной почты по умолчанию, который пользователь вручную отправляет из предложения, нажав кнопку «Отправить по электронной почте», и появится мастер.
где я ошибаюсь.
вот мой код.

@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')

person kryptonian    schedule 16.08.2020    source источник


Ответы (1)


хорошо, я получил решение своего собственного вопроса.
в контроллере я написал это до 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'))
person kryptonian    schedule 17.08.2020