コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
296 ビュー

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

アバター
破棄
最善の回答

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

アバター
破棄
関連投稿 返信 ビュー 活動
2
7月 25
524
1
7月 25
284
2
7月 25
326
3
6月 25
974
0
6月 25
243