[FIX] account: Journal is overwritteng in payments by onchange

There is an onchange on payments that, when the currency is modified,
sets the journal to the first available one whose currency matches the
selected one. However, if a journal is already set, its value is
overwritten, even if its currency matches the new one.

To replicate:
- Create two banks in EUR
- Create an internal transfer from the second bank
- Set the payment currency to EUR

When you follow the above steps, the payment journal will be incorrectly
set to the first bank.

Other possible ways to replicate the issue are:
- When editing a payment already created whose journal is correct but
  whose currency is not
- When creating a payment and the journal is set before the currency

This commit fixes that issue by preventing the onchange from modifying
the journal, when it's already set.

Closes odoo/odoo#30967

closes odoo/odoo#30969
This commit is contained in:
Luis González
2019-02-11 15:59:09 +00:00
parent 7ecd750a77
commit d1b9c2f377
+2
View File
@@ -211,6 +211,8 @@ class account_abstract_payment(models.AbstractModel):
self.amount = abs(self._compute_payment_amount())
# Set by default the first liquidity journal having this currency if exists.
if self.journal_id:
return
journal = self.env['account.journal'].search(
[('type', 'in', ('bank', 'cash')), ('currency_id', '=', self.currency_id.id)], limit=1)
if journal: