From b8473a60c86de0a0aa0638faeb3ee974fa1427bc Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 30 Nov 2023 08:55:55 +0100 Subject: [PATCH] account_import_helper: block if an account code has a double entry in the imported file --- account_import_helper/account.py | 2 +- account_import_helper/wizard/account_chart_generate.py | 9 +++++---- .../wizard/account_chart_generate_view.xml | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/account_import_helper/account.py b/account_import_helper/account.py index 3a1f697..05b367b 100644 --- a/account_import_helper/account.py +++ b/account_import_helper/account.py @@ -76,7 +76,7 @@ def generate_custom_chart( } ) custom_code_size = False - for (custom_code, src_custom_dict) in custom_chart: + for custom_code, src_custom_dict in custom_chart.items(): if fixed_size_code: if custom_code_size: if len(custom_code) != custom_code_size: diff --git a/account_import_helper/wizard/account_chart_generate.py b/account_import_helper/wizard/account_chart_generate.py index 76ba14e..4a728dc 100644 --- a/account_import_helper/wizard/account_chart_generate.py +++ b/account_import_helper/wizard/account_chart_generate.py @@ -50,7 +50,7 @@ def run(self): fileobj.seek(0) wb = openpyxl.load_workbook(fileobj.name, read_only=True) sh = wb.active - custom_chart = [] + custom_chart = {} i = 0 for row in sh.rows: i += 1 @@ -67,9 +67,10 @@ def run(self): if not code[:3].isdigit(): raise UserError( _("Account '%s': the 3 first caracters are not digits") % code) - custom_chart.append( - (code, {"name": name, "note": note}) - ) + if code in custom_chart: + raise UserError(_( + "Double entry in the chart of account: account '%s'.") % code) + custom_chart[code] = {"name": name, "note": note} fileobj.close() pprint(custom_chart) logger.info("Starting to generate CSV file") diff --git a/account_import_helper/wizard/account_chart_generate_view.xml b/account_import_helper/wizard/account_chart_generate_view.xml index 36b8f1f..fb08024 100644 --- a/account_import_helper/wizard/account_chart_generate_view.xml +++ b/account_import_helper/wizard/account_chart_generate_view.xml @@ -72,6 +72,7 @@ id="account_chart_generate_parent_menu" parent="base.menu_custom" name="Chart Generate" + sequence="-1" />