简体   繁体   中英

How to call bank informations when there are more than one bank account

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 id s 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM