diff --git a/src/app/blueprints/admin/routes.py b/src/app/blueprints/admin/routes.py index 7a392c7..fa14396 100644 --- a/src/app/blueprints/admin/routes.py +++ b/src/app/blueprints/admin/routes.py @@ -10,6 +10,11 @@ def add_product(tenant_id): """Add a new product""" custom_fields = ARFieldModel.get_all(tenant_id) + # Prevent adding products if no fields are configured + if not custom_fields: + flash('Cannot add products. Please configure AR fields first.', 'warning') + return redirect(url_for('admin.manage_ar_fields', tenant_id=tenant_id)) + if request.method == 'POST': product_id = request.form.get('product_id') diff --git a/src/app/models/base.py b/src/app/models/base.py index 6aa7ff6..31e1775 100644 --- a/src/app/models/base.py +++ b/src/app/models/base.py @@ -8,6 +8,8 @@ def get_db(): db_path = current_app.config['DATABASE_PATH'] conn = sqlite3.connect(db_path) conn.row_factory = sqlite3.Row + # Enable foreign key constraints + conn.execute('PRAGMA foreign_keys = ON') try: yield conn finally: diff --git a/src/app/templates/admin/add_product.html b/src/app/templates/admin/add_product.html index d38843b..7df582f 100644 --- a/src/app/templates/admin/add_product.html +++ b/src/app/templates/admin/add_product.html @@ -10,6 +10,21 @@

Add New Product

+ {% if not custom_fields %} + + {% else %}
@@ -71,6 +86,7 @@
+ {% endif %}
diff --git a/src/app/templates/index.html b/src/app/templates/index.html index 714a997..beac3fa 100644 --- a/src/app/templates/index.html +++ b/src/app/templates/index.html @@ -16,6 +16,18 @@
+ {% if not custom_fields %} + + {% else %}

Products

@@ -27,7 +39,7 @@
- + {% if products %}
@@ -91,6 +103,7 @@ No products available yet. Click "Add New Product" to get started. {% endif %} + {% endif %}