Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
1645 Lượt xem

Hello.

I am trying to create an automated action that when a user creates a purchase request, an email is automatically sent with the quote request template, this is my code:




Enviar correos al generar una solicitud de presupuesto en compras


email
on_create



It works perfectly, if you execute the action, but now what I'm trying to do is send that same email to other specific users, I'm trying to do the search through their ids in res.users, but when creating a purchase request, it doesn't do That function doesn't even execute the print that I have in the log...

can you help me?

# -*- coding: utf-8 -*-

from odoo import models, fields, api


class PurchaseOrder(models.Model):
_inherit = 'purchase.order'

@api.model
def create(self, vals):
res = super(PurchaseOrder, self).create(vals)
usuarios = self.env['res.users'].search([('id', 'in', [8, 9])])
if usuarios:
for order in self:
template = self.env.ref('purchase.email_template_edi_purchase')
for usuario in usuarios:
if usuario.email:
try:
template.send_mail(order.id, force_send=True, email_to=usuario.email)
except Exception as e:
print(f"Error sending email to {usuario.email}: {e}")

return res

Thanks, odoo 13 community.

Note: the outgoing email servers are configured correctly, but I repeat, the function does not even create the email, it does not create anything.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Change the line of code:  for order in self:  to for order in res      and see if it makes any difference,

Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

Ok, now at least it prints the except prints and it gives me this error: Error sending email to mail@gmail.com: send_mail() got an unexpected keyword argument 'email_to', I will search from here on out, thanks for your help and sorry for the inconvenience caused.

Tác giả

I was now able to solve the problem, thank you very much for your help!

Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 12 24
2287
2
thg 5 24
1775
1
thg 4 24
1473
3
thg 6 23
10336
2
thg 2 25
1157