0

I'm working with Odoo 14 eCommerce module for shop and I'm customising email template (Sales: Order Confirmation).

I would like to show bank information which are already inserted on Accounting / Bank Accounts section of the company contact information such as; bank name, account holder name, account number etc.

I'm calling those values like this in the template:

${object.company_id.bank_ids.acc_holder_name}
${object.company_id.bank_ids.bank_name}
${object.company_id.bank_ids.acc_number}

When there is only one bank account defined, I get the right values without problem, but as soon as I add a second bank account, I get this error below:

Failed to render template : Expected singleton: res.partner.bank(2, 3)

I understand that there are ids of bank accounts, but I don't know what is the right way to indicate the id of the bank account which I want to get the value. Any idea?

Syfer
  • 4,262
  • 3
  • 20
  • 37
george
  • 610
  • 6
  • 16

1 Answers1

1

You should loop over the bank records in the email template, this way:

% for bank in object.company_id.bank_ids:
    <li>${bank.acc_holder_name}</li>
    <li>${bank.bank_name}</li>
    <li>${bank.acc_number}</li>
% endfor

If you want to do some action inside the loop depending on the ID of the bank account you should do this:

% for bank in object.company_id.bank_ids:
    % if bank.id == 2:
        <li>${bank.acc_holder_name}</li>
        <li>${bank.bank_name}</li>
        <li>${bank.acc_number}</li>
    % endif
% endfor

However, performing an action depending on the database ID is not recommended since your module may won't work in any database. You must value yourself if it's worth it in this particular case.

forvas
  • 9,801
  • 7
  • 62
  • 158
  • Thanks for the answer @forvas. I tried it. I have two bank accounts and in this way, it lists both of them. If I add the order number (like this: `% for bank in object.company_id.bank_ids[0]:`), I get only the first ones values. I was wondering if I can get values base on the bank account id. Something like that: `% if id in object.company_id.bank_ids == 2:`? Do you have any idea? – george Jan 19 '23 at 17:14
  • I've edited my answer with what I think you were asking for in the comment. Please, if the answer is useful for you, give it an upvote, if the answer is the right one, set it as correct, and if you have another different question, open a new one. – forvas Jan 20 '23 at 09:43
  • Thanks @forvas, this is exactly what I was looking for. Also, I clearly understand your point and you're right. – george Jan 20 '23 at 10:36