Hi there,
i want to automatically send an email to each customer for whom a delivery has been made with the following data.
the delivery note, the invoice and the Invoice in an excel format
thank you so much for the help
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hi there,
i want to automatically send an email to each customer for whom a delivery has been made with the following data.
the delivery note, the invoice and the Invoice in an excel format
thank you so much for the help
Hi,
Create a server action on the stock.picking model (Delivery Orders)
Trigger: On Validation (when the delivery is marked “Done”)
Action: Execute Python Code → send email with attachments.
for picking in records:
if picking.picking_type_id.code == 'outgoing' and picking.state == 'done':
# Get customer
partner = picking.partner_id
# Generate Delivery Slip PDF
delivery_pdf = env['ir.actions.report']._render_qweb_pdf('stock.report_deliveryslip', picking.id)[0]
# Get related invoices
invoices = picking.sale_id.invoice_ids.filtered(lambda inv: inv.state == 'posted')
attachments = []
# Attach Delivery Slip
attachments.append(('Delivery_Slip.pdf', delivery_pdf))
for inv in invoices:
# Invoice PDF
inv_pdf = env['ir.actions.report']._render_qweb_pdf('account.report_invoice', inv.id)[0]
attachments.append((f'Invoice_{inv.name}.pdf', inv_pdf))
# Invoice Excel (custom report needed)
inv_xlsx = env['ir.actions.report']._render_qweb_xlsx('your_module.report_invoice_xlsx', inv.id)[0]
attachments.append((f'Invoice_{inv.name}.xlsx', inv_xlsx))
# Send email
mail = env['mail.mail'].create({
'subject': f"Delivery and Invoice for {picking.name}",
'body_html': f"<p>Dear {partner.name},<br/>Please find attached your delivery note and invoice.</p>",
'email_to': partner.email,
'attachment_ids': [
(0, 0, {'name': fname, 'datas': base64.b64encode(data), 'res_model': 'mail.mail'})
for fname, data in attachments
]
})
mail.send()
Hope it helps.
Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!
RekisteröidyAiheeseen liittyviä artikkeleita | Vastaukset | Näkymät | Toimenpide | |
---|---|---|---|---|
|
2
maalisk. 25
|
1289 | ||
|
1
elok. 22
|
2790 | ||
|
2
heinäk. 24
|
5033 | ||
|
2
huhtik. 20
|
5228 | ||
|
2
toukok. 16
|
10974 |