Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
213 Tampilan

Como envio un email automaticamente a varios usuarios de las ventas diarias u otro reporte ??

Avatar
Buang
Jawaban Terbai

Hi,


By using the automated scheduled action, we can send the email at a particular interval of time. To achieve this, refer to the following 


https://www.cybrosys.com/blog/how-to-configure-automated-actions-in-odoo-18

https://www.cybrosys.com/blog/how-to-configure-scheduled-actions-in-odoo-18



Try the following.


today = fields.Date.today()
start = datetime.combine(today, datetime.min.time())
end = datetime.combine(today, datetime.max.time())

# Get today's confirmed sales
orders = env['sale.order'].search([
('date_order', '>=', start),
('date_order', '<=', end),
('state', 'in', ['sale', 'done'])
])

total_sales = sum(orders.mapped('amount_total'))
order_count = len(orders)

# Prepare email content
subject = f"Daily Sales Report: {today.strftime('%Y-%m-%d')}"
body = f"""
Dear Team,<br/><br/>
Here is the sales summary for {today.strftime('%Y-%m-%d')}:<br/>
- Total Orders: {order_count}<br/>
- Total Sales: ${total_sales:.2f}<br/><br/>
Regards,<br/>
Odoo
"""

# Target recipients: user emails
user_emails = env['res.users'].search([('groups_id.name', '=', 'Sales')]).mapped('partner_id.email')

# Send emails
mail = env['mail.mail']
for email in user_emails:
if email:
mail.create({
'subject': subject,
'email_to': email,
'body_html': body,
}).send()


Hope it helps

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
1
Jul 25
425
1
Jul 25
188
2
Jul 25
259
3
Jun 25
920
0
Jun 25
188