Show the intake lineage and edit controls on the batch detail page

This commit is contained in:
ixgadmin 2026-09-17 14:48:23 +00:00
parent b4d6d4bb20
commit be2da9c6e4

View file

@ -4,7 +4,11 @@
<div class="page-header d-flex justify-content-between align-items-center">
<h2>Batch: {{ batch.batch_reference }}</h2>
<a href="{% url 'ops:batch_list' %}" class="btn btn-sm btn-outline-secondary"><i class="bi bi-arrow-left"></i> Back</a>
<div>
<a href="{% url 'ops:batch_lineage' batch.pk %}" class="btn btn-sm btn-primary"><i class="bi bi-basket"></i> Edit intake lineage</a>
<a href="{% url 'ops:batch_update' batch.pk %}" class="btn btn-sm btn-outline-primary"><i class="bi bi-pencil"></i> Edit batch</a>
<a href="{% url 'ops:batch_list' %}" class="btn btn-sm btn-outline-secondary"><i class="bi bi-arrow-left"></i> Back</a>
</div>
</div>
<div class="row g-3 mb-4">
@ -29,6 +33,73 @@
</div>
</div>
<div class="row g-3 mb-4">
<div class="col-12">
<div class="stat-card">
<div class="d-flex justify-content-between align-items-center mb-3">
<h6 class="mb-0">Intake Lineage ({{ lineage|length }})</h6>
<a href="{% url 'ops:batch_lineage' batch.pk %}" class="btn btn-sm btn-outline-primary"><i class="bi bi-basket"></i> Edit lineage</a>
</div>
{% if lineage %}
<table class="table table-sm mb-0">
<thead>
<tr>
<th>Intake</th>
<th>Date</th>
<th>Received (kg)</th>
<th>Allocated (kg)</th>
<th>Origin Zone</th>
<th>Collector Group</th>
</tr>
</thead>
<tbody>
{% for row in lineage %}
<tr>
<td><strong>{{ row.harvest_intake.intake_reference }}</strong></td>
<td>{{ row.harvest_intake.intake_date|date:'d/m/Y'|default:'-' }}</td>
<td>{{ row.harvest_intake.weight_kg|default:'-' }}</td>
<td>{{ row.weight_allocated_kg|default:'-' }}</td>
<td>
{% if row.harvest_intake.origin_zone %}
{{ row.harvest_intake.origin_zone.zone_code }}
{% if row.harvest_intake.origin_zone.verification_status != 'verified' %}
<span class="badge bg-warning text-dark">{{ row.harvest_intake.origin_zone.get_verification_status_display }}</span>
{% endif %}
{% else %}-{% endif %}
</td>
<td>{{ row.harvest_intake.collector_group.name|default:'-' }}</td>
</tr>
{% endfor %}
<tr class="table-light">
<td colspan="3" class="text-end text-secondary">Total allocated</td>
<td><strong>{{ lineage_allocated }}</strong></td>
<td colspan="2" class="text-secondary">batch weight {{ batch.weight_kg|default:'-' }} kg</td>
</tr>
</tbody>
</table>
{% if lineage_difference > 0 %}
<p class="small text-secondary mt-2 mb-0">
{{ lineage_difference }} kg of this batch is not traced back to a harvest intake.
The platform shows the two figures side by side; it does not reconcile them.
</p>
{% elif lineage_difference < 0 %}
<p class="small text-secondary mt-2 mb-0">
The allocated weights are above the batch weight &mdash; the usual direction,
since processing loses weight. The platform shows the two figures side by
side; it does not reconcile them.
</p>
{% endif %}
{% else %}
<p class="text-muted mb-0">
No harvest intakes are linked to this batch. Until at least one is, this
batch cannot be traced back to a collector group and an origin zone, and
the due-diligence case for it will fail its lineage check.
</p>
{% endif %}
</div>
</div>
</div>
<div class="row g-3 mb-4">
<div class="col-md-6">
<div class="stat-card">