0

When using the accounting module in Odoo 10. I've problem with the default e-mail template would like to send the invoice to the e-mail address of the company instead of the invoice contact that I've assigned to the company.

It seems like you can edit a template for the e-mail and the to-field is set to ${object.partner_id.id} how can I find the corresponding code for the company invoice contact?

I found out that the user object has a type property. When that property is set to 'invoice' that user is the linked company invoice contact. But cannot connect the company on the invoice to it's users and test the type property.

skyshaper
  • 1
  • 3
  • Please [edit] your question to show [the code you have so far](http://whathaveyoutried.com). You should include at least an outline (but preferably a [mcve]) of the code that you are having problems with, then we can try to help with the specific problem. You should also read [ask]. – Toby Speight Sep 05 '17 at 16:04
  • Tried to be more specific but there isn't so much coding involved here... for now ;-) – skyshaper Sep 05 '17 at 16:19

1 Answers1

1

You can try accessing back to the Sales Order from the invoice object.

${object.sale_id.partner_id.id}

However, if there's no sale_id (typically this would only be for manually created invoices), you'll probably want to identify a fallback for the template to use. In this case, it's going to use the Sales Order's Partner ID, otherwise the Invoice's partner ID.

${object.sale_id.partner_id.id or object.partner_id.id}

The above could potentially cause an error if there's no sale_id, so you may have to do something a little more clunky such as:

${object.sale_id and object.sale_id.partner_id.id or object.partner_id.id}
travisw
  • 2,052
  • 1
  • 14
  • 27
  • Guess I might found a issue with my idea. Apparently a company can have several contacts marked as invoice address. Guess that kind of rule out any automation in picking a contact to send an invoice to. So a Sale to connect to would be the best but not applicable to my situation :-/ – skyshaper Sep 06 '17 at 17:11
  • @skyshaper Maybe I'm not understanding what you're trying to do. Tell me, do you have multiple addresses on your sales orders? If not, you can turn it on by going to **Sales > Configuration > Settings** and turning on **Display 3 fields on sales orders: customer, invoice address, delivery address** in the *Addresses* setting field. – travisw Sep 06 '17 at 17:19
  • I don't have any sales order because I'm not selling anything. Just want to invoice a membership fee to all current members(companies) and all companies has several contacts but just one 'invoice contact'. Perhaps I should not try to violate the model and register a proper sale for each member. – skyshaper Sep 06 '17 at 17:39