diff --git a/account_move_base_import/models/account_journal.py b/account_move_base_import/models/account_journal.py index e6eabd01..c62ae71d 100644 --- a/account_move_base_import/models/account_journal.py +++ b/account_move_base_import/models/account_journal.py @@ -245,7 +245,6 @@ class AccountJournal(models.Model): 'debit_cash_basic': values['debit'], 'credit_cash_basic': values['credit'], 'balance_cash_basic': values['debit'] - values['credit'], - 'ref': move.ref, 'user_type_id': account.user_type_id.id, 'reconciled': False, }) @@ -277,11 +276,13 @@ class AccountJournal(models.Model): parser = new_move_parser(self, ftype=ftype, move_ref=filename) res = self.env['account.move'] for result_row_list in parser.parse(file_stream): - move = self._move_import(parser, file_stream, ftype=ftype) + move = self._move_import( + parser, file_stream, result_row_list=result_row_list, ftype=ftype + ) res |= move return res - def _move_import(self, parser, file_stream, ftype="csv"): + def _move_import(self, parser, file_stream, result_row_list=None, ftype="csv"): """Create a bank statement with the given profile and parser. It will fulfill the bank statement with the values of the file provided, but will not complete data (like finding the partner, or the right @@ -296,7 +297,8 @@ class AccountJournal(models.Model): move_obj = self.env['account.move'] move_line_obj = self.env['account.move.line'] attachment_obj = self.env['ir.attachment'] - result_row_list = parser.result_row_list + if result_row_list is None: + result_row_list = parser.result_row_list # Check all key are present in account.bank.statement.line!! if not result_row_list: raise UserError(_("Nothing to import: " diff --git a/account_move_base_import/parser/file_parser.py b/account_move_base_import/parser/file_parser.py index 8893b96b..3eaa3f32 100644 --- a/account_move_base_import/parser/file_parser.py +++ b/account_move_base_import/parser/file_parser.py @@ -57,6 +57,8 @@ class FileParser(AccountMoveImportParser): # Set in _parse_xls, from the contents of the file self.dialect = dialect self.move_ref = move_ref + self.parsed_file = None + self.current_line = 0 def _custom_format(self, *args, **kwargs): """No other work on data are needed in this parser.""" @@ -70,13 +72,24 @@ class FileParser(AccountMoveImportParser): """Launch the parsing through .csv, .xls or .xlsx depending on the given ftype """ - res = None - if self.ftype == 'csv': - res = self._parse_csv() + if self.parsed_file is None: + if self.ftype == 'csv': + self.parsed_file = self._parse_csv() + else: + self.parsed_file = self._parse_xls() + if self.support_multi_moves: + if len(self.parsed_file) <= self.current_line: + return False + else: + print(self.current_line) + self.result_row_list = self.parsed_file[ + self.current_line:self.current_line + 1 + ] + self.current_line += 1 + return True else: - res = self._parse_xls() - self.result_row_list = res - return True + self.result_row_list = self.parsed_file + return True def _validate(self, *args, **kwargs): """We check that all the key of the given file (means header) are