diff --git a/containers/backupchecks/src/backend/app/main/routes_customers.py b/containers/backupchecks/src/backend/app/main/routes_customers.py index 996d95d..eb5e1ec 100644 --- a/containers/backupchecks/src/backend/app/main/routes_customers.py +++ b/containers/backupchecks/src/backend/app/main/routes_customers.py @@ -505,6 +505,7 @@ def customers_export(): @roles_required("admin", "operator") def customers_import(): file = request.files.get("file") + include_autotask_ids = bool(request.form.get("include_autotask_ids")) if not file or not getattr(file, "filename", ""): flash("No file selected.", "warning") return redirect(url_for("main.customers")) @@ -541,10 +542,11 @@ def customers_import(): # Detect Autotask columns (backwards compatible - these are optional) autotask_id_idx = None autotask_name_idx = None - if "autotask_company_id" in header: - autotask_id_idx = header.index("autotask_company_id") - if "autotask_company_name" in header: - autotask_name_idx = header.index("autotask_company_name") + if include_autotask_ids: + if "autotask_company_id" in header: + autotask_id_idx = header.index("autotask_company_id") + if "autotask_company_name" in header: + autotask_name_idx = header.index("autotask_company_name") for r in rows[start_idx:]: if not r: @@ -582,7 +584,7 @@ def customers_import(): if active_val is not None: existing.active = active_val # Update Autotask mapping if provided in CSV - if autotask_company_id is not None: + if include_autotask_ids and autotask_company_id is not None: existing.autotask_company_id = autotask_company_id existing.autotask_company_name = autotask_company_name existing.autotask_mapping_status = None # Will be resynced @@ -600,7 +602,10 @@ def customers_import(): try: db.session.commit() - flash(f"Import finished. Created: {created}, Updated: {updated}, Skipped: {skipped}.", "success") + flash( + f"Import finished. Created: {created}, Updated: {updated}, Skipped: {skipped}. Autotask IDs imported: {'yes' if include_autotask_ids else 'no'}.", + "success", + ) # Audit logging import json @@ -609,6 +614,7 @@ def customers_import(): f"Imported customers from CSV", details=json.dumps({ "format": "CSV", + "include_autotask_ids": include_autotask_ids, "created": created, "updated": updated, "skipped": skipped @@ -620,4 +626,3 @@ def customers_import(): flash("Failed to import customers.", "danger") return redirect(url_for("main.customers")) - diff --git a/containers/backupchecks/src/backend/app/main/routes_settings.py b/containers/backupchecks/src/backend/app/main/routes_settings.py index dc68bf1..6d5173a 100644 --- a/containers/backupchecks/src/backend/app/main/routes_settings.py +++ b/containers/backupchecks/src/backend/app/main/routes_settings.py @@ -585,6 +585,7 @@ def settings_jobs_export(): @roles_required("admin") def settings_jobs_import(): upload = request.files.get("jobs_file") + include_autotask_ids = bool(request.form.get("include_autotask_ids")) if not upload or not upload.filename: flash("No import file was provided.", "danger") return redirect(url_for("main.settings", section="general")) @@ -621,14 +622,17 @@ def settings_jobs_import(): if not cust_name: continue - # Read Autotask fields (backwards compatible - optional) - autotask_company_id = cust_item.get("autotask_company_id") - autotask_company_name = cust_item.get("autotask_company_name") + autotask_company_id = None + autotask_company_name = None + if include_autotask_ids: + # Read Autotask fields (backwards compatible - optional) + autotask_company_id = cust_item.get("autotask_company_id") + autotask_company_name = cust_item.get("autotask_company_name") existing_customer = Customer.query.filter_by(name=cust_name).first() if existing_customer: - # Update Autotask mapping if provided - if autotask_company_id is not None: + # Update Autotask mapping only when explicitly allowed by import option. + if include_autotask_ids and autotask_company_id is not None: existing_customer.autotask_company_id = autotask_company_id existing_customer.autotask_company_name = autotask_company_name existing_customer.autotask_mapping_status = None # Will be resynced @@ -747,7 +751,7 @@ def settings_jobs_import(): db.session.commit() flash( - f"Import completed. Customers created: {created_customers}, updated: {updated_customers}. Jobs created: {created_jobs}, updated: {updated_jobs}.", + f"Import completed. Customers created: {created_customers}, updated: {updated_customers}. Jobs created: {created_jobs}, updated: {updated_jobs}. Autotask IDs imported: {'yes' if include_autotask_ids else 'no'}.", "success", ) @@ -758,6 +762,7 @@ def settings_jobs_import(): details=json.dumps({ "format": "JSON", "schema": payload.get("schema"), + "include_autotask_ids": include_autotask_ids, "customers_created": created_customers, "customers_updated": updated_customers, "jobs_created": created_jobs, diff --git a/containers/backupchecks/src/templates/main/customers.html b/containers/backupchecks/src/templates/main/customers.html index d418636..4a78bf7 100644 --- a/containers/backupchecks/src/templates/main/customers.html +++ b/containers/backupchecks/src/templates/main/customers.html @@ -15,6 +15,10 @@
diff --git a/containers/backupchecks/src/templates/main/settings.html b/containers/backupchecks/src/templates/main/settings.html index aa79d88..f9920a3 100644 --- a/containers/backupchecks/src/templates/main/settings.html +++ b/containers/backupchecks/src/templates/main/settings.html @@ -528,8 +528,16 @@