[FIX] account: Clean inconsistent currencies when creating statement lines
foreign_currency_id & currency_id must always be different on a statement line. However, this happens sometimes when importing statement lines in csv. closes odoo/odoo#109574 X-original-commit: 0b2cb4c82fa38ca1242c2344546768e481841116 Related: odoo/enterprise#35630 Signed-off-by: Laurent Smet <las@odoo.com> Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -330,6 +330,14 @@ class AccountBankStatementLine(models.Model):
|
||||
if statement.journal_id:
|
||||
vals['journal_id'] = statement.journal_id.id
|
||||
|
||||
# Avoid having the same foreign_currency_id as currency_id.
|
||||
if vals.get('journal_id') and vals.get('foreign_currency_id'):
|
||||
journal = self.env['account.journal'].browse(vals['journal_id'])
|
||||
journal_currency = journal.currency_id or journal.company_id.currency_id
|
||||
if vals['foreign_currency_id'] == journal_currency.id:
|
||||
vals['foreign_currency_id'] = None
|
||||
vals['amount_currency'] = 0.0
|
||||
|
||||
# Force the move_type to avoid inconsistency with residual 'default_move_type' inside the context.
|
||||
vals['move_type'] = 'entry'
|
||||
|
||||
|
||||
@@ -369,12 +369,6 @@ class TestAccountBankStatementLine(AccountTestInvoicingCommon):
|
||||
|
||||
# ==== Test constraints at creation ====
|
||||
|
||||
# Foreign currency must not be the same as the journal one.
|
||||
assertStatementLineConstraint({
|
||||
**statement_line_vals,
|
||||
'foreign_currency_id': self.currency_1.id,
|
||||
})
|
||||
|
||||
# Can't have a stand alone amount in foreign currency without foreign currency set.
|
||||
assertStatementLineConstraint({
|
||||
**statement_line_vals,
|
||||
@@ -1170,3 +1164,20 @@ class TestAccountBankStatementLine(AccountTestInvoicingCommon):
|
||||
'balance_start': 0, # no value is given for balance start and it is not a split
|
||||
'balance_end': 0,
|
||||
}])
|
||||
|
||||
def test_create_statement_line_with_inconsistent_currencies(self):
|
||||
statement_line = self.env['account.bank.statement.line'].create({
|
||||
'date': '2019-01-01',
|
||||
'journal_id': self.bank_journal_1.id,
|
||||
'payment_ref': "Happy new year",
|
||||
'amount': 200.0,
|
||||
'amount_currency': 200.0,
|
||||
'foreign_currency_id': self.env.company.currency_id.id,
|
||||
})
|
||||
|
||||
self.assertRecordValues(statement_line, [{
|
||||
'currency_id': self.env.company.currency_id.id,
|
||||
'foreign_currency_id': False,
|
||||
'amount': 200.0,
|
||||
'amount_currency': 0.0,
|
||||
}])
|
||||
|
||||
Reference in New Issue
Block a user