Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
3616 Переглядів

Hi everybody, 


I´m working on our templates at the moment. (We are using Version 14) 

In the tab Email Configuration the To (Emails) and To (Partners) field is currently empty and the Emails are send to all emails set in the contact.


I would like to add a code that it should use a set email under an invoice address (Child) first. Only if there is no invoice with an special email it should be send to the standard address. 


Hopefully you can help. 


Thanks in advance    .

Melanie 

 

Аватар
Відмінити
Найкраща відповідь

Very annoying, this is just a bug really. I don´t think you can change it in the email template by using the jinja syntax, there are too many limitations built in. 

So finally i put an additional field in the partner model:

invoice_ids = fields.Char(
string="Invoice Email", compute="_compute_invoice_email", store=False
)

@api.depends("child_ids.email", "child_ids.type", "email")
def _compute_invoice_email(self):
for partner in self:
invoice_contacts = partner.child_ids.filtered(
lambda c: c.type == "invoice" and c.email
)
if invoice_contacts:
partner.invoice_ids = ",".join(
[str(id) for id in invoice_contacts.mapped("id")]
)
else:
partner.invoice_ids = ",".join(partner.id)

In the template, you need to point to this field in the right box:



Аватар
Відмінити

Hi Hendrik,
thank you very much, your code is what I also was looking for!
I want to share my improvement. It is only to add both emails, the one from the invoice person and also the one from the company.
class ResPartner(models.Model):
_inherit = "res.partner"

invoice_emails = fields.Char(
string="Invoice Email", compute="_compute_invoice_emails", store=False
)

@api.depends("child_ids.email", "child_ids.type", "email")
def _compute_invoice_emails(self):
for partner in self:
contact_ids = []

# Includes company ID if has email
if partner.email:
contact_ids.append(str(partner.id))

# Includes contacts IDs type invoice with email
invoice_contacts = partner.child_ids.filtered(
lambda c: c.type == "invoice" and c.email
)
contact_ids += [str(contact.id) for contact in invoice_contacts]

# Remove duplicates (if there are) and join
partner.invoice_emails = ",".join(sorted(set(contact_ids)))

Just wanted to add a comment (I cannot edit nor delete). It works in Odoo18 and I changed the name invoice_ids for invoice_emails (I thought invoice_ids can be used by Odoo and so I wanted to avoid problems). Therefore, the code for the Email template is {{ (object.partner_id.invoice_emails) }} .

Найкраща відповідь

Hi

I don't know odoo 14 (i'm on v16) and don't have a field "invoice address" but as far this is an object from res_partner this should work as email:

(Assuming the invoice child is invoice_partner_id)

 {{ object.invoice_partner_id.id or object.partner_id.id }}

Regards

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
0
січ. 25
1534
1
вер. 22
1322
0
трав. 20
3081
3
бер. 15
10931
0
бер. 15
4880