diff --git a/account_move_base_import/models/account_journal.py b/account_move_base_import/models/account_journal.py index f2833be2..3572ee1b 100644 --- a/account_move_base_import/models/account_journal.py +++ b/account_move_base_import/models/account_journal.py @@ -60,7 +60,7 @@ class AccountJournal(models.Model): launch_import_completion = fields.Boolean( string="Launch completion after import", - help="Tic that box to automatically launch the completion " + help="Tick that box to automatically launch the completion " "on each imported file using this journal.", ) @@ -81,6 +81,11 @@ class AccountJournal(models.Model): string="Commission Analytic Account", help="Choose an analytic account to be used on the commission line.", ) + autovalidate_completed_move = fields.Boolean( + string="Validate fully completed moves", + help="Tick that box to automatically validate the journal entries " + "after the completion", + ) def _prepare_counterpart_line(self, move, amount, date): if amount > 0.0: @@ -269,6 +274,16 @@ class AccountJournal(models.Model): vals.update(parser.get_move_vals()) return vals + def _get_attachment_data(self, moves, file_stream, ftype): + attachment_data = { + "name": "statement file", + "datas": file_stream, + "store_fname": "{}.{}".format(fields.Date.today(), ftype), + "res_model": "account.move", + "res_id": moves[0].id, + } + return attachment_data + def multi_move_import(self, file_stream, ftype="csv"): """Create multiple bank statements from values given by the parser for the given profile. @@ -279,6 +294,7 @@ class AccountJournal(models.Model): :return: list: list of ids of the created account.bank.statement """ filename = self._context.get("file_name", None) + attachment_obj = self.env["ir.attachment"] if filename: (filename, __) = os.path.splitext(filename) parser = new_move_parser(self, ftype=ftype, move_ref=filename) @@ -291,6 +307,10 @@ class AccountJournal(models.Model): ftype=ftype, ) res |= move + if res: + attachment_vals = self._get_attachment_data(res, file_stream, ftype) + if attachment_vals: + attachment_obj.create(attachment_vals) return res def _move_import(self, parser, file_stream, result_row_list=None, ftype="csv"): diff --git a/account_move_base_import/models/account_move.py b/account_move_base_import/models/account_move.py index 704fdad4..a3311640 100644 --- a/account_move_base_import/models/account_move.py +++ b/account_move_base_import/models/account_move.py @@ -391,5 +391,9 @@ class AccountMove(models.Model): st += "".join(traceback.format_tb(trbk, 30)) _logger.error(st) msg = "\n".join(msg_lines) - self.write_completion_log(msg, compl_lines) + move.write_completion_log(msg, compl_lines) + if move.journal_id.autovalidate_completed_move and all( + [line.already_completed for line in move.line_ids] + ): + move._post() return True diff --git a/account_move_base_import/views/journal_view.xml b/account_move_base_import/views/journal_view.xml index 03e6af81..eb93b708 100644 --- a/account_move_base_import/views/journal_view.xml +++ b/account_move_base_import/views/journal_view.xml @@ -21,6 +21,10 @@ ('used_for_import', '=', False), ('used_for_completion', '=', False)]}" /> +