This question has been flagged

Having different bank accounts in different currencies, is it possible to configure Odoo so that when creating customer invoice and selecting, for example the Euro currency, automatically my Euro bank account will be set in the Recipient Bank?


Odoo simply takes the first company account from the top which causes errors, an Automatic Action to take the first account in the currency/journal currrency selected in invoice could be a solution.


Avatar
Discard
Best Answer

This worked for me:


Model: Journal Entry

Trigger: On Creation & Update

Action to do: Execute Python Code

Python Code:

for record in records:
  if record.move_type == 'out_invoice':
    currency = record.currency_id
    bank_account = record.env['res.partner.bank'].search([('currency_id', '=', currency.id)], limit=1)
    if bank_account:
        record.write({'partner_bank_id': bank_account.id})

Update: You can set currency.id as a trigger field, although this was not necessary in my case as all fields are monitored if empty.

Avatar
Discard
Author

thanks Patrick, but maybe missing trigger fields or something else?

Thanks, this did help - I have just extended it slightly in my answer.

Best Answer

It's really surprising that there is no easier way to solve this. I had the same issue and found this thread, but the examples were not fully working for me. They did select a bank account, but not necessarily one which is linked to the own company.


This seems to work (tested in Odoo 17, but should work in Odoo 16 too):


for record in records:
if record.move_type == 'out_invoice':
  currency = record.currency_id
bank_account = record.env['res.partner.bank'].search(['&', ('currency_id', '=', currency.id), ('partner_id', '=', record.env.company.partner_id.id)], limit=1)
    if bank_account:
        record.write({'partner_bank_id': bank_account.id})



I have set the trigger on "currency" too, but it is not necessary. Hope it helps!

Avatar
Discard
Best Answer

I would need exactly that, but the provided code does not work in Odoo 16. @Ricardo: Were you able to solve this?

Avatar
Discard
Author

unfortunately not yet

Best Answer

Hi,

Yes, for this you can create an automatic action that triggers when a new invoice is created or updated. The automatic action should set the recipient bank account based on the currency selected in the invoice.

for move in records:
if move.type == 'out_invoice':
currency = move.currency_id
bank_account = self.env['res.partner.bank'].search([('currency_id', '=', currency.id)], limit=1)
if bank_account:
move.write({'partner_bank_id': bank_account.id})


Once the automatic action is created, it will be triggered when a new invoice is created or updated. It will set the recipient bank account based on the currency selected in the invoice.

Note that this solution assumes that you have created separate bank accounts for each currency. If you have not done so already, you will need to create a separate bank account for each currency in your chart of accounts.


Regards

Avatar
Discard
Author

thanks for your solution.
But either I'm doing something wrong or the automated action code is not correct, as when I test and change the invoice currency, the recipient bank remains always the same. Have you tested your solution in v16?