콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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.


아바타
취소
베스트 답변

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.

아바타
취소
작성자

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

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

작성자

for v18 it also works by setting the trigger "on save” and adding Apply on “status = Draft"

베스트 답변

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!

아바타
취소
베스트 답변

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

아바타
취소
작성자

unfortunately not yet

베스트 답변

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

아바타
취소
작성자

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?

관련 게시물 답글 화면 활동
1
2월 24
2696
0
2월 23
2399
3
10월 23
3164
1
10월 23
2185
2
7월 24
2938