Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
3457 Widoki

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!


Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
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!

Powiązane posty Odpowiedzi Widoki Czynność
2
mar 24
1951
1
lut 17
21101
1
wrz 24
1484
1
kwi 22
3751
1
lut 24
2425