[FIX] account_bank_statement_import_online: catch any exception

This commit is contained in:
Alexey Pelykh
2020-03-23 08:14:37 +01:00
parent 703f928a5f
commit b8fbb95fca
3 changed files with 38 additions and 10 deletions

View File

@@ -1,10 +1,11 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) # Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2019 Dataplug (https://dataplug.io) # Copyright 2019-2020 Dataplug (https://dataplug.io)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from dateutil.relativedelta import relativedelta, MO from dateutil.relativedelta import relativedelta, MO
from decimal import Decimal from decimal import Decimal
import logging import logging
from sys import exc_info
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from odoo.addons.base.models.res_bank import sanitize_account_number from odoo.addons.base.models.res_bank import sanitize_account_number
@@ -167,7 +168,8 @@ class OnlineBankStatementProvider(models.Model):
statement_date_since, statement_date_since,
statement_date_until statement_date_until
) )
except Exception as e: except:
e = exc_info()[1]
if is_scheduled: if is_scheduled:
_logger.warning( _logger.warning(
'Online Bank Statement Provider "%s" failed to' 'Online Bank Statement Provider "%s" failed to'
@@ -186,7 +188,7 @@ class OnlineBankStatementProvider(models.Model):
provider.name, provider.name,
statement_date_since, statement_date_since,
statement_date_until, statement_date_until,
str(e), str(e) if e else _('N/A'),
), ),
subject=_( subject=_(
'Online Bank Statement Provider failure' 'Online Bank Statement Provider failure'

View File

@@ -1,5 +1,5 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) # Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2019 Dataplug (https://dataplug.io) # Copyright 2019-2020 Dataplug (https://dataplug.io)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from datetime import datetime, timedelta from datetime import datetime, timedelta
@@ -22,7 +22,11 @@ class OnlineBankStatementProviderDummy(models.Model):
) # pragma: no cover ) # pragma: no cover
if self.env.context.get('crash', False): if self.env.context.get('crash', False):
raise Exception('Expected') exception = self.env.context.get(
'exception',
Exception('Expected')
)
raise exception
line_step_options = self.env.context.get('step', { line_step_options = self.env.context.get('step', {
'minutes': 5, 'minutes': 5,

View File

@@ -1,10 +1,10 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) # Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2019 Dataplug (https://dataplug.io) # Copyright 2019-2020 Dataplug (https://dataplug.io)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from psycopg2 import IntegrityError from psycopg2 import IntegrityError
from urllib.error import HTTPError
from odoo.tests import common from odoo.tests import common
from odoo.tools import mute_logger from odoo.tools import mute_logger
@@ -341,3 +341,25 @@ class TestAccountBankAccountStatementImportOnline(common.TransactionCase):
self.now - relativedelta(hours=1), self.now - relativedelta(hours=1),
self.now, self.now,
) )
def test_pull_httperror(self):
journal = self.AccountJournal.create({
'name': 'Bank',
'type': 'bank',
'code': 'BANK',
'bank_statements_source': 'online',
'online_bank_statement_provider': 'dummy',
})
provider = journal.online_bank_statement_provider_id
provider.active = True
provider.statement_creation_mode = 'weekly'
with self.assertRaises(HTTPError):
provider.with_context(
crash=True,
exception=HTTPError(None, 500, 'Error', None, None),
)._pull(
self.now - relativedelta(hours=1),
self.now,
)