Fix foreign key cascades and add validation for missing AR fields

- Enable SQLite foreign key constraints to properly cascade deletes
- Add validation to prevent adding products when no AR fields configured
- Display helpful warnings on product pages when fields are missing
- Redirect users to AR field configuration when needed
This commit is contained in:
2025-10-20 21:36:01 -04:00
parent a727796ed2
commit 03b4264239
4 changed files with 37 additions and 1 deletions

View File

@@ -10,6 +10,21 @@
<h2>Add New Product</h2>
</div>
<div class="card-body">
{% if not custom_fields %}
<div class="alert alert-warning" role="alert">
<h4 class="alert-heading"><i class="bi bi-exclamation-triangle-fill me-2"></i>No Fields Configured</h4>
<p>Unable to add products. You must configure custom AR fields before adding products.</p>
<hr>
<p class="mb-0">
<a href="/{{ tenant_id }}/ar_fields" class="btn btn-primary">
<i class="bi bi-gear-fill me-1"></i>Configure AR Fields
</a>
<a href="/{{ tenant_id }}/" class="btn btn-secondary ms-2">
<i class="bi bi-arrow-left me-1"></i>Back to Products
</a>
</p>
</div>
{% else %}
<form action="/{{ tenant_id }}/add" method="POST" enctype="multipart/form-data">
<div class="mb-3">
<label for="product_id" class="form-label">Product ID *</label>
@@ -71,6 +86,7 @@
<button type="submit" class="btn btn-primary">Add Product</button>
</div>
</form>
{% endif %}
</div>
</div>
</div>

View File

@@ -16,6 +16,18 @@
<hr class="my-4">
<div class="mt-4">
{% if not custom_fields %}
<div class="alert alert-warning" role="alert">
<h4 class="alert-heading"><i class="bi bi-exclamation-triangle-fill me-2"></i>No AR Fields Configured</h4>
<p>Before you can add products, you need to configure custom AR fields that define what information is returned for each product.</p>
<hr>
<p class="mb-0">
<a href="/{{ tenant.id }}/ar_fields" class="btn btn-primary">
<i class="bi bi-gear-fill me-1"></i>Configure AR Fields
</a>
</p>
</div>
{% else %}
<div class="d-flex justify-content-between align-items-center mb-3">
<h2>Products</h2>
<div>
@@ -27,7 +39,7 @@
</a>
</div>
</div>
{% if products %}
<div class="table-responsive">
<table class="table table-striped table-hover">
@@ -91,6 +103,7 @@
<i class="bi bi-info-circle"></i> No products available yet. Click "Add New Product" to get started.
</div>
{% endif %}
{% endif %}
</div>
<div class="mt-4">