diff --git a/account_bank_statement_import/account_bank_statement_import.py b/account_bank_statement_import/account_bank_statement_import.py index 37ff851..a9ef252 100644 --- a/account_bank_statement_import/account_bank_statement_import.py +++ b/account_bank_statement_import/account_bank_statement_import.py @@ -197,9 +197,13 @@ class account_bank_statement_import(osv.TransientModel): # while 'counterpart' bank accounts (from which statement transactions originate) don't. # Warning : if company_id is set, the method post_write of class bank will create a journal if journal_id: - vals_acc['partner_id'] = uid + company_id = self.pool['account.journal'].browse( + cr, uid, journal_id, context=context).company_id.id + vals = self.pool['res.partner.bank'].onchange_company_id( + cr, uid, None, company_id, context=None) + vals_acc.update(vals.get('value', {})) vals_acc['journal_id'] = journal_id - vals_acc['company_id'] = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id + vals_acc['company_id'] = company_id return self.pool.get('res.partner.bank').create(cr, uid, vals_acc, context=context) diff --git a/account_bank_statement_import/tests/__init__.py b/account_bank_statement_import/tests/__init__.py new file mode 100644 index 0000000..c3f445c --- /dev/null +++ b/account_bank_statement_import/tests/__init__.py @@ -0,0 +1,2 @@ +# -*- encoding: utf-8 -*- +from . import test_import_bank_statement diff --git a/account_bank_statement_import/tests/test_import_bank_statement.py b/account_bank_statement_import/tests/test_import_bank_statement.py new file mode 100644 index 0000000..1c9f7fa --- /dev/null +++ b/account_bank_statement_import/tests/test_import_bank_statement.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This file is part of account_bank_statement_import, +# an Odoo module. +# +# Copyright (c) 2015 ACSONE SA/NV () +# +# account_bank_statement_import is free software: +# you can redistribute it and/or modify it under the terms of the GNU +# Affero General Public License as published by the Free Software +# Foundation,either version 3 of the License, or (at your option) any +# later version. +# +# account_bank_statement_import is distributed +# in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with account_bank_statement_import_coda. +# If not, see . +# +############################################################################## +from openerp.tests.common import TransactionCase + + +class TestAccountBankStatemetImport(TransactionCase): + """Tests for import bank statement file import + (account.bank.statement.import) + """ + + def setUp(self): + super(TestAccountBankStatemetImport, self).setUp() + self.statement_import_model = self.env[ + 'account.bank.statement.import'] + self.account_journal_model = self.env['account.journal'] + self.res_users_model = self.env['res.users'] + + self.journal_id = self.ref('account.bank_journal') + self.base_user_root_id = self.ref('base.user_root') + self.base_user_root = self.res_users_model.browse( + self.base_user_root_id) + + # create a new user that belongs to the same company as + # user_root + self.other_partner_id = self.env['res.partner'].create( + {"name": "My other partner", + "is_company": False, + "email": "test@tes.ttest", + }) + company_id = self.base_user_root.company_id.id + self.other_user_id_a = self.res_users_model.create( + {"partner_id": self.other_partner_id.id, + "company_id": company_id, + "company_ids": [(4, company_id)], + "login": "my_login a", + "name": "my user", + "groups_id": [(4, self.ref('account.group_account_manager'))] + }) + + def test_create_bank_account(self): + """Checks that the bank_account created by the import belongs to the + partner linked to the company of the provided journal + """ + journal = self.account_journal_model.browse(self.journal_id) + expected_id = journal.company_id.partner_id.id + + st_import = self.statement_import_model.sudo(self.other_user_id_a.id) + bank_id = st_import._create_bank_account( + '001251882303', journal_id=self.journal_id) + bank = self.env['res.partner.bank'].browse(bank_id) + + self.assertEqual(bank.partner_id.id, + expected_id)