From d1f54ac00927a0b2b8b21230ac469a4b689785ff Mon Sep 17 00:00:00 2001 From: Kaynnan Lemes Date: Tue, 12 Aug 2025 17:16:58 -0300 Subject: [PATCH] [IMP] account_move_csv_import: support 'date_maturity' field in CSV, ODS, XLS, and XLSX imports --- .../wizard/account_move_import.py | 23 ++++++++++++++++++- .../wizard/account_move_import_view.xml | 3 +++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/account_move_csv_import/wizard/account_move_import.py b/account_move_csv_import/wizard/account_move_import.py index 459ea4c..83b9438 100644 --- a/account_move_csv_import/wizard/account_move_import.py +++ b/account_move_csv_import/wizard/account_move_import.py @@ -112,6 +112,9 @@ class AccountMoveImport(models.TransientModel): file_with_header = fields.Boolean( string='Has Header Line', help="Indicate if the first line is a header line and should be ignored.") + use_date_maturity = fields.Boolean( + string='Use Date Maturity', + help='If enabled, the import will use the date maturity field from the file.') @api.depends('file_format') def _compute_force_required(self): @@ -366,7 +369,7 @@ def genericcsv2pivot(self, fileobj): fieldnames = [ 'date', 'journal', 'account', 'partner', 'analytic', 'name', 'debit', 'credit', - 'ref', 'reconcile_ref', 'move_name', + 'ref', 'reconcile_ref', 'move_name', 'date_maturity', ] # I use utf-8-sig instead of utf-8 to transparently handle BOM # https://en.wikipedia.org/wiki/Byte_order_mark @@ -402,6 +405,7 @@ def genericcsv2pivot(self, fileobj): 'ref': l.get('ref', ''), 'reconcile_ref': l.get('reconcile_ref', ''), 'move_name': l.get('move_name', ''), + 'date_maturity': l.get('date_maturity', ''), 'line': i, } if l['analytic']: @@ -448,6 +452,7 @@ def genericxlsx2pivot(self, fileobj): 'ref': len(row) > 8 and row[8].value or '', 'reconcile_ref': len(row) > 9 and row[9].value or '', 'move_name': len(row) > 10 and row[10].value or '', + 'date_maturity': len(row) > 11 and row[11].value or False, 'line': i, } res.append(vals) @@ -484,6 +489,7 @@ def genericxls2pivot(self, fileobj): 'credit': row[7].value, 'ref': len(row) > 8 and row[8].value or '', 'reconcile_ref': len(row) > 9 and row[9].value or '', + 'date_maturity': len(row) > 11 and row[11].value and datetime(*xlrd.xldate_as_tuple(row[11].value, wb.datemode)) or False, 'line': i, } res.append(vals) @@ -509,6 +515,7 @@ def genericods2pivot(self, fileobj): ('credit', rows.fields.FloatField), ('ref', rows.fields.TextField), ('reconcile_ref', rows.fields.TextField), + ('date_maturity', rows.fields.DateField), ]) sh = rows.import_from_ods(fileobj.name, fields=fields_ods, skip_header=False) @@ -531,6 +538,7 @@ def genericods2pivot(self, fileobj): 'credit': row.credit, 'ref': row.ref, 'reconcile_ref': row.reconcile_ref, + 'date_maturity': getattr(row, 'date_maturity', False), 'line': i, } res.append(vals) @@ -904,6 +912,19 @@ def _prepare_move_line(self, pivot_line, sequence): 'import_reconcile': pivot_line.get('reconcile_ref'), 'import_external_id': '%s-%s' % (sequence, pivot_line.get('line')), } + + if self.use_date_maturity and pivot_line.get('date_maturity'): + try: + if isinstance(pivot_line['date_maturity'], str): + vals['date_maturity'] = datetime.strptime( + pivot_line['date_maturity'], self.date_format) + else: + vals['date_maturity'] = pivot_line['date_maturity'] + except Exception: + logger.warning( + "Could not parse date maturity '%s' for line %s", + pivot_line['date_maturity'], pivot_line.get('line')) + return vals def reconcile_move_lines(self, moves): diff --git a/account_move_csv_import/wizard/account_move_import_view.xml b/account_move_csv_import/wizard/account_move_import_view.xml index 687edf1..dd23ad2 100644 --- a/account_move_csv_import/wizard/account_move_import_view.xml +++ b/account_move_csv_import/wizard/account_move_import_view.xml @@ -20,6 +20,7 @@ + @@ -63,6 +64,7 @@
  • Ref (used as Journal Entry Ref)
  • Reconcile ref (used for reconciliation after import)
  • Journal entry number
  • +
  • Due Date (DD/MM/YYYY or configurable, optional)
  • @@ -80,6 +82,7 @@ I. Ref (used as Journal Entry Ref)
    J. Reconcile Ref (used for reconciliation after import)
    K. Journal Entry Number
    + L. Due Date (must be a date field in the spreadsheet, optional)