Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
2291 Vizualizări

Hello, I have an API that creates the customer details and paid invoices in odoo. When the invoice is created I want to send the invoice as a pdf to the customer automatically. This is my code, it is not working. Please review it

    @api.model

    def send_membership_invoice_emails(self):

        invoices = self.env['account.move'].search([('invoice_line_ids.product_id.name', '=', 'Product membership') ])

        for invoice in invoices:

            _logger.info("Product 'Product membership' found in invoice %s. Proceeding to send email.", invoice.name)

            invoice_report_id = self.env.ref('account.account_invoices_without_payment')

            generated_report = invoice_report_id._render_qweb_pdf(invoice.id, email_values=email_values, force_send=True)

                email_template.attachment_ids = [(5, 0, 0)]

                _logger.info("Email sent successfully to %s for invoice %s", invoice.partner_id.email, invoice.name)

Imagine profil
Abandonează

Which odoo version sir ?

Autor

odoo 16

Cel mai bun răspuns

Hi,
The shared code seems to be not tested at all, what does the email_template variable refers to in the code ? of course the shared code will raise exception.

First of all get the external id of your email template, if you already have created it, so let the email template variable hold that information.

request_template = self.env.ref('my_module.id_of_template', raise_if_not_found=False)

request_template.send_mail(invoice.id)


The above code will generate the email based on the template provided and pass the record and send it to the specified to address.

Also inside the email template, in the dynamic reports column, set the needed pdf report, so that the report will go along with the email.






Thanks

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
iun. 15
5983
2
iul. 19
4053
0
mai 19
4121
5
iul. 17
5991
1
iun. 17
3552