Skip to content

Commit

Permalink
[IMP] account_move_csv_import: add field date_maturity only for CSV a…
Browse files Browse the repository at this point in the history
…nd XLSX
  • Loading branch information
kaynnan committed Apr 2, 2024
1 parent 15d779f commit 0d92f5a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
27 changes: 26 additions & 1 deletion account_move_csv_import/wizard/import_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class AccountMoveImport(models.TransientModel):
force_move_date_required = fields.Boolean('Force Date Required')
force_move_line_name_required = fields.Boolean('Force Label Required')
force_journal_required = fields.Boolean('Force Journal Required')
include_date_maturity = fields.Boolean('Include Date Maturity')
advanced_options = fields.Boolean()
# START GENERIC advanced options
date_by_move_line = fields.Boolean(
Expand Down Expand Up @@ -329,7 +330,7 @@ def genericcsv2pivot(self, fileobj):
fieldnames = [
'date', 'journal', 'account', 'partner',
'analytic', 'name', 'debit', 'credit',
'ref', 'reconcile_ref'
'ref', 'reconcile_ref', 'date_maturity'
]
first_line = fileobj.readline().decode()
dialect = unicodecsv.Sniffer().sniff(first_line)
Expand All @@ -356,6 +357,19 @@ def genericcsv2pivot(self, fileobj):
raise UserError(_(
"Date parsing error: '%s' in line %s does not match "
"date format '%s'.") % (date_str, i, self.date_format))
if self.include_date_maturity:
date_maturity_str = l['date_maturity']
if date_maturity_str:
try:
date_maturity = datetime.strptime(date_maturity_str, self.date_format)
except ValueError:
raise UserError(_(
"Date Maturity parsing error: '%s' in line %s does not match "
"date format '%s'.") % (date_maturity_str, i, self.date_format))
else:
date_maturity = False
else:
date_maturity = False

vals = {
'journal': l['journal'],
Expand All @@ -366,6 +380,7 @@ def genericcsv2pivot(self, fileobj):
'name': l['name'],
'ref': l.get('ref', ''),
'reconcile_ref': l.get('reconcile_ref', ''),
'date_maturity': date_maturity,
'line': i,
}
if l['analytic']:
Expand All @@ -389,6 +404,11 @@ def genericxlsx2pivot(self, fileobj):
if not [item for item in row if item.value]:
# skip empty line
continue
if self.include_date_maturity:
date_maturity = row[11].value
else:
date_maturity = False

vals = {
'date': row[0].value,
'journal': row[1].value,
Expand All @@ -401,6 +421,7 @@ def genericxlsx2pivot(self, fileobj):
'ref': len(row) > 8 and row[8].value or '',
'reconcile_ref': len(row) > 9 and row[9].value or '',
'analytic_tags': len(row) > 10 and row[10].value or '',
'date_maturity': date_maturity,
'line': i,
}
res.append(vals)
Expand Down Expand Up @@ -736,6 +757,10 @@ 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')),
}
# Adding date_maturity only if it exists in pivot_line
# This validation is temporary as date_maturity implementation is currently for CSV and XLSX file types only
if 'date_maturity' in pivot_line:
vals['date_maturity'] = pivot_line['date_maturity']
return vals

def reconcile_move_lines(self, moves):
Expand Down
3 changes: 3 additions & 0 deletions account_move_csv_import/wizard/import_move_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<field name="file_encoding" attrs="{'invisible': [('file_format', 'not in', ('fec_txt', 'quadra'))], 'required': [('file_format', 'in', ('fec_txt', 'quadra'))]}"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="post_move" />
<field name="include_date_maturity" attrs="{'invisible': [('file_format', 'not in', ('genericxlsx', 'genericcsv'))]}"/>
<field name="force_journal_id" attrs="{'required': [('force_journal_required', '=', True)]}"/>
<field name="force_move_date" attrs="{'required': [('force_move_date_required', '=', True)]}"/>
<field name="force_move_ref" />
Expand Down Expand Up @@ -55,6 +56,7 @@
<li>Credit</li>
<li>Ref (used as Journal Entry Ref)</li>
<li>Reconcile ref (used for reconciliation after import)</li>
<li>Date Maturity (DD/MM/YYYY or configurable)</li>
</ol></li>
<li><em>Encoding</em>: UTF-8</li>
<li><em>Field separator</em>: auto-detected</li>
Expand All @@ -76,6 +78,7 @@
I. Ref (used as Journal Entry Ref)<br/>
J. Reconcile Ref (used for reconciliation after import)<br/>
K. Analytic Tags (separated by coma)<br/>
L. Date Maturity (DD/MM/YYYY or configurable)<br/>
</p>
</div>

Expand Down

0 comments on commit 0d92f5a

Please sign in to comment.