Skip to content

Commit

Permalink
VTB statement import: fix for period header placement variations
Browse files Browse the repository at this point in the history
  • Loading branch information
titov-vv committed Apr 13, 2024
1 parent c754af0 commit 9e9f36f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion jal/data_import/broker_statements/vtb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

# ----------------------------------------------------------------------------------------------------------------------
class StatementVTB(StatementXLS):
PeriodPattern = (7, 1, r"Отчет Банка ВТБ \(ПАО\) за период с (?P<S>\d\d\.\d\d\.\d\d\d\d) по (?P<E>\d\d\.\d\d\.\d\d\d\d) о сделках, .*")
# VTB changed header placment and it may be shifted left or right
PeriodPattern = ([5, 7], 1, r"Отчет Банка ВТБ \(ПАО\) за период с (?P<S>\d\d\.\d\d\.\d\d\d\d) по (?P<E>\d\d\.\d\d\.\d\d\d\d) о сделках, .*")
AccountPattern = (9, 7, None)
HeaderCol = 1
money_section = "Отчет об остатках денежных средств"
Expand Down
18 changes: 10 additions & 8 deletions jal/data_import/statement_xls.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,16 @@ def _check_statement_header(self):
self.tr("Can't find expected report header: ") + f"'{self.Header[2]}'")

def _get_statement_period(self):
parts = re.match(self.PeriodPattern[2],
self._statement[self.PeriodPattern[0]][self.PeriodPattern[1]], re.IGNORECASE)
if parts is None:
raise Statement_ImportError(self.tr("Can't read report period"))
statement_dates = parts.groupdict()
start_day = int(datetime.strptime(statement_dates['S'], "%d.%m.%Y").replace(tzinfo=timezone.utc).timestamp())
end_day = int(datetime.strptime(statement_dates['E'], "%d.%m.%Y").replace(tzinfo=timezone.utc).timestamp())
self._data[FOF.PERIOD] = [start_day, self._end_of_date(end_day)]
column_list = self.PeriodPattern[0] if type(self.PeriodPattern[0]) == list else [self.PeriodPattern[0]]
for column in column_list:
parts = re.match(self.PeriodPattern[2], self._statement[column][self.PeriodPattern[1]], re.IGNORECASE)
if parts is not None:
statement_dates = parts.groupdict()
start_day = int(datetime.strptime(statement_dates['S'], "%d.%m.%Y").replace(tzinfo=timezone.utc).timestamp())
end_day = int(datetime.strptime(statement_dates['E'], "%d.%m.%Y").replace(tzinfo=timezone.utc).timestamp())
self._data[FOF.PERIOD] = [start_day, self._end_of_date(end_day)]
return
raise Statement_ImportError(self.tr("Can't read report period from XLS statement"))

def _get_account_number(self):
if self.AccountPattern[2] is None:
Expand Down

0 comments on commit 9e9f36f

Please sign in to comment.