From b0e16df208ae01ef1abb5a0710c0b398d5f3c755 Mon Sep 17 00:00:00 2001 From: Tom Blauwendraat Date: Wed, 7 Feb 2018 19:52:21 +0100 Subject: [PATCH] [FIX] #145 --- .../models/account_bank_statement_import.py | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/account_bank_statement_import/models/account_bank_statement_import.py b/account_bank_statement_import/models/account_bank_statement_import.py index 3fbfbfd..280b3e6 100644 --- a/account_bank_statement_import/models/account_bank_statement_import.py +++ b/account_bank_statement_import/models/account_bank_statement_import.py @@ -345,16 +345,22 @@ class AccountBankStatementImport(models.TransientModel): bank_account_id = False partner_account_number = line_vals.get('account_number') if partner_account_number: - bank_model = self.env['res.partner.bank'] - banks = bank_model.search( - [('acc_number', '=', partner_account_number)], limit=1) - if banks: - bank_account_id = banks[0].id - partner_id = banks[0].partner_id.id - else: - bank_obj = self._create_bank_account( - partner_account_number) - bank_account_id = bank_obj and bank_obj.id or False + partner_model = self.env['res.partner'] + partner_with_bank = partner_model.search([ + ('bank_ids.acc_number', '=', partner_account_number) + ], limit=1) + if partner_with_bank: + bank_model = self.env['res.partner.bank'] + banks = bank_model.search([ + ('acc_number', '=', partner_account_number) + ], limit=1) + if banks: + bank_account_id = banks[0].id + partner_id = banks[0].partner_id.id + else: + bank_obj = self._create_bank_account( + partner_account_number) + bank_account_id = bank_obj and bank_obj.id or False line_vals['partner_id'] = partner_id line_vals['bank_account_id'] = bank_account_id if 'date' in stmt_vals and 'period_id' not in stmt_vals: