Skip to Content
Menu
This question has been flagged
2 Replies
3447 Zobrazenia

Hi Everybody


We've ran into the following issue:


Invoice App:

We added a many2many field (additional_recipients) in our invoice app (account.move). It is filled from a similar field in res.partner, which contains the additional contacts for each partner.

The goal is, that invoices are automatically sent to the contacts, selected in this field.


Mail Template:

The field partner_to in the mail.template, now has the following value: 

{{ object.partner_id.id }}, {{ object.additional_recipients.id }}


Error Messages:

In case the there are no additional contacts, the mail template runs into a value error because there is no ID from which it would get an email-address

ValueError: invalid literal for int() with base 10: ' ' 

In case there are multiple contacts selected, it runs into an error because the partner_to field expects singleton expressions. Meaning, that it works as long as there is only one contact in the field. 

Failed to render inline_template template : : "Expected singleton: res.partner(2728, 3374)" while evaluating' object.additional_recipients.id ')


Do you have an idea how to fix this issue without coding too much?


Kind regards, and thank you in advance!


Avatar
Zrušiť
Best Answer

Hello,

I was faced with the same problem. The only difference was that I was trying to do it without code but directly on email template through Odoo interface.

Thanks to technical colleague, I manage to do it. I think it can help you and others facing same issue.

Here the solution :
Odoo version : v17 EE

The need : Add several contacts to an existing customer in order to declare several followup contacts. When sending a followup email, if at least a followup contact is defined, I needed to add all those contacts as recipients, else I only add customer contact as recipient.

I needed to create a many2many field on res_partner model. I did it with studio : x_studio_followup_contacts.

On the dedicated email template linked to account.move I created : in to (email) field I put this value 

{{ ','.join(object.partner_id.x_studio_followup_contacts.mapped('email')) if object.partner_id.x_studio_followup_contacts else object.partner_id.email }}

I tried it and it work wonderfully.

Kind regards

Avatar
Zrušiť
Best Answer

Hi

Try to add the partner_to in the given format 

<field name="partner_to">{{object.partner_id.id and object.additional_recipients.ids }}</field>


Hope it helps

Avatar
Zrušiť
Autor

Hi

Thank you very much for the quick reply.

Unfortunately, that doesn't work either.

No additional recipient -> No contact (not even the partner_id.id) is added as a recipient
1 additional recipients -> ValueError: invalid literal for int() with base 10: '[4081]'
2 or more additional recipients -> ValueError: invalid literal for int() with base 10: '[4061]'

Worst case, maybe I could create a concatenated string out of the recipient's email-addresses. But that would be a rather dirty workaround :)

Do you, by chance, have another idea?

Thanks again and kind regards!

Related Posts Replies Zobrazenia Aktivita
2
mar 24
1949
1
feb 17
21096
1
sep 24
1483
1
apr 22
3748
1
feb 24
2423