2020-03-20 23:52:26 +00:00
|
|
|
{% extends "base.html" %}
|
2020-08-25 16:10:21 +00:00
|
|
|
{% comment %}
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
{% endcomment %}
|
|
|
|
{% load i18n crispy_forms_tags %}
|
|
|
|
{% block contenttitle %}{% endblock %}
|
2020-08-06 20:30:14 +00:00
|
|
|
|
2020-08-25 16:10:21 +00:00
|
|
|
{% block content %}
|
|
|
|
<div class="card bg-white mb-3">
|
|
|
|
<h3 class="card-header text-center">
|
|
|
|
{{ title }}
|
|
|
|
</h3>
|
|
|
|
<div class="card-body">
|
|
|
|
{% if object.pk and not object.locked %}
|
2020-08-06 20:30:14 +00:00
|
|
|
<div class="alert alert-info">
|
|
|
|
{% blocktrans trimmed %}
|
2020-08-25 16:10:21 +00:00
|
|
|
Warning: the LaTeX template is saved with this object. Updating the invoice implies regenerate it.
|
|
|
|
Be careful if you manipulate old invoices.
|
2020-08-06 20:30:14 +00:00
|
|
|
{% endblocktrans %}
|
|
|
|
</div>
|
2020-08-25 16:10:21 +00:00
|
|
|
{% elif object.locked %}
|
2020-08-07 09:04:54 +00:00
|
|
|
<div class="alert alert-info">
|
|
|
|
{% blocktrans trimmed %}
|
2020-08-25 16:10:21 +00:00
|
|
|
This invoice is locked and can no longer be edited.
|
2020-08-07 09:04:54 +00:00
|
|
|
{% endblocktrans %}
|
|
|
|
</div>
|
2020-08-25 16:10:21 +00:00
|
|
|
{% endif %}
|
|
|
|
</div>
|
2020-08-06 20:30:14 +00:00
|
|
|
|
2020-03-21 17:59:13 +00:00
|
|
|
<form method="post" action="">
|
2020-03-21 15:49:18 +00:00
|
|
|
{% csrf_token %}
|
2020-08-25 16:10:21 +00:00
|
|
|
|
2020-03-24 19:22:15 +00:00
|
|
|
{# Render the invoice form #}
|
2020-08-25 16:10:21 +00:00
|
|
|
<div class="card-body">
|
|
|
|
{% crispy form %}
|
|
|
|
</div>
|
|
|
|
|
2020-03-24 19:22:15 +00:00
|
|
|
{# The next part concerns the product formset #}
|
|
|
|
{# Generate some hidden fields that manage the number of products, and make easier the parsing #}
|
2020-03-21 15:49:18 +00:00
|
|
|
{{ formset.management_form }}
|
|
|
|
<table class="table table-condensed table-striped">
|
2020-03-24 19:22:15 +00:00
|
|
|
{# Fill initial data #}
|
|
|
|
{% for form in formset %}
|
2020-08-25 16:10:21 +00:00
|
|
|
{% if forloop.first %}
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>{{ form.designation.label }}<span class="asteriskField">*</span></th>
|
|
|
|
<th>{{ form.quantity.label }}<span class="asteriskField">*</span></th>
|
|
|
|
<th>{{ form.amount.label }}<span class="asteriskField">*</span></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody id="form_body">
|
2020-03-24 19:22:15 +00:00
|
|
|
{% endif %}
|
|
|
|
<tr class="row-formset">
|
2020-03-21 15:49:18 +00:00
|
|
|
<td>{{ form.designation }}</td>
|
2020-03-27 12:50:02 +00:00
|
|
|
<td>{{ form.quantity }}</td>
|
|
|
|
<td>{{ form.amount }}</td>
|
2020-03-24 19:22:15 +00:00
|
|
|
{# These fields are hidden but handled by the formset to link the id and the invoice id #}
|
2020-03-22 00:22:27 +00:00
|
|
|
{{ form.invoice }}
|
2020-03-21 15:49:18 +00:00
|
|
|
{{ form.id }}
|
2020-03-24 19:22:15 +00:00
|
|
|
</tr>
|
2020-08-25 16:10:21 +00:00
|
|
|
{% endfor %}
|
2020-03-24 19:22:15 +00:00
|
|
|
</tbody>
|
2020-03-21 15:49:18 +00:00
|
|
|
</table>
|
|
|
|
|
2020-03-24 19:22:15 +00:00
|
|
|
{# Display buttons to add and remove products #}
|
2020-08-25 16:10:21 +00:00
|
|
|
<div class="card-body">
|
|
|
|
{% if not object.locked %}
|
2020-08-07 09:04:54 +00:00
|
|
|
<div class="btn-group btn-block" role="group">
|
2020-08-25 16:10:21 +00:00
|
|
|
<button type="button" id="add_more" class="btn btn-success">{% trans "Add product" %}</button>
|
2020-08-07 09:04:54 +00:00
|
|
|
<button type="button" id="remove_one" class="btn btn-danger">{% trans "Remove product" %}</button>
|
|
|
|
</div>
|
2020-08-25 16:10:21 +00:00
|
|
|
{% endif %}
|
2020-03-21 15:49:18 +00:00
|
|
|
|
|
|
|
<button type="submit" class="btn btn-block btn-primary">{% trans "Submit" %}</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
2020-08-25 16:10:21 +00:00
|
|
|
</div>
|
2020-03-21 15:49:18 +00:00
|
|
|
|
2020-08-25 16:10:21 +00:00
|
|
|
{# Hidden div that store an empty product form, to be copied into new forms #}
|
|
|
|
<div id="empty_form" style="display: none;">
|
|
|
|
<table class='no_error'>
|
|
|
|
<tbody id="for_real">
|
2020-03-24 19:22:15 +00:00
|
|
|
<tr class="row-formset">
|
|
|
|
<td>{{ formset.empty_form.designation }}</td>
|
|
|
|
<td>{{ formset.empty_form.quantity }} </td>
|
2020-03-27 12:50:02 +00:00
|
|
|
<td>{{ formset.empty_form.amount }}</td>
|
2020-03-24 19:22:15 +00:00
|
|
|
{{ formset.empty_form.invoice }}
|
|
|
|
{{ formset.empty_form.id }}
|
|
|
|
</tr>
|
2020-08-25 16:10:21 +00:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2020-03-21 15:49:18 +00:00
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block extrajavascript %}
|
2020-08-25 16:10:21 +00:00
|
|
|
<script>
|
|
|
|
/* script that handles add and remove lines */
|
|
|
|
IDS = {};
|
2020-03-21 15:49:18 +00:00
|
|
|
|
2020-08-25 16:10:21 +00:00
|
|
|
$("#id_products-TOTAL_FORMS").val($(".row-formset").length - 1);
|
2020-03-21 15:49:18 +00:00
|
|
|
|
2020-08-25 16:10:21 +00:00
|
|
|
$('#add_more').click(function () {
|
|
|
|
let form_idx = $('#id_products-TOTAL_FORMS').val();
|
|
|
|
$('#form_body').append($('#for_real').html().replace(/__prefix__/g, form_idx));
|
|
|
|
$('#id_products-TOTAL_FORMS').val(parseInt(form_idx) + 1);
|
|
|
|
$('#id_products-' + parseInt(form_idx) + '-id').val(IDS[parseInt(form_idx)]);
|
|
|
|
});
|
2020-03-21 15:49:18 +00:00
|
|
|
|
2020-08-25 16:10:21 +00:00
|
|
|
$('#remove_one').click(function () {
|
|
|
|
let form_idx = $('#id_products-TOTAL_FORMS').val();
|
|
|
|
if (form_idx > 0) {
|
|
|
|
IDS[parseInt(form_idx) - 1] = $('#id_products-' + (parseInt(form_idx) - 1) + '-id').val();
|
|
|
|
$('#form_body tr:last-child').remove();
|
|
|
|
$('#id_products-TOTAL_FORMS').val(parseInt(form_idx) - 1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
{% endblock %}
|