Add FuelPurchase model, List, Create views and templates
This commit is contained in:
parent
64576a7f09
commit
fa19b593d8
10 changed files with 242 additions and 4 deletions
51
main/templates/main/fuelpurchase_add.html
Normal file
51
main/templates/main/fuelpurchase_add.html
Normal file
|
@ -0,0 +1,51 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Add Fuel Purchase{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2 class="uk-heading-line"><span>Add Fuel Purchase</span></h2>
|
||||
|
||||
<form method="post" class="uk-form-stacked">
|
||||
{% csrf_token %}
|
||||
|
||||
{% for field in form %}
|
||||
<div class="uk-margin">
|
||||
<label class="uk-form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
|
||||
<div class="uk-form-controls">
|
||||
{{ field }}
|
||||
{% if field.help_text %}
|
||||
<p class="uk-text-meta">{{ field.help_text }}</p>
|
||||
{% endif %}
|
||||
{% for error in field.errors %}
|
||||
<p class="uk-text-danger">{{ error }}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<button type="submit" class="uk-button uk-button-primary">Save</button>
|
||||
<a href="{% url 'fuelpurchase_list' %}" class="uk-button uk-button-default">Cancel</a>
|
||||
|
||||
</form>
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const totalCostInput = document.getElementById("id_total_cost");
|
||||
const pricePerLitreInput = document.getElementById("id_price_per_litre");
|
||||
const amountLitresInput = document.getElementById("id_amount_litres");
|
||||
|
||||
function updateAmountLitres() {
|
||||
const total = parseFloat(totalCostInput.value);
|
||||
const price = parseFloat(pricePerLitreInput.value);
|
||||
if (!isNaN(total) && !isNaN(price) && price > 0) {
|
||||
amountLitresInput.value = (total / price).toFixed(2);
|
||||
} else {
|
||||
amountLitresInput.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
totalCostInput.addEventListener("input", updateAmountLitres);
|
||||
pricePerLitreInput.addEventListener("input", updateAmountLitres);
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
35
main/templates/main/fuelpurchase_list.html
Normal file
35
main/templates/main/fuelpurchase_list.html
Normal file
|
@ -0,0 +1,35 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Fuel Purchases{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="uk-flex uk-flex-between uk-flex-middle uk-margin-bottom">
|
||||
<h2 class="uk-heading-line"><span>Fuel Purchases</span></h2>
|
||||
<a href="{% url 'fuelpurchase_add' %}" class="uk-button uk-button-primary">Add Purchase</a>
|
||||
</div>
|
||||
|
||||
{% if purchases %}
|
||||
<table class="uk-table uk-table-divider uk-table-striped uk-table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Total Cost (€)</th>
|
||||
<th>Price/Litre (€)</th>
|
||||
<th>Amount (litres)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for purchase in purchases %}
|
||||
<tr>
|
||||
<td>{{ purchase.purchase_date|date:"d.m.Y" }}</td>
|
||||
<td>{{ purchase.total_cost }}</td>
|
||||
<td>{{ purchase.price_per_litre }}</td>
|
||||
<td>{{ purchase.amount_litres }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="uk-text-meta">No purchases recorded yet.</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue