2020-03-20 23:52:26 +00:00
|
|
|
{% extends "base.html" %}
|
|
|
|
{% load static %}
|
|
|
|
{% load i18n %}
|
2020-03-21 17:59:13 +00:00
|
|
|
{% load crispy_forms_tags pretty_money %}
|
2020-03-20 23:52:26 +00:00
|
|
|
{% block content %}
|
2020-03-22 00:22:27 +00:00
|
|
|
<p><a class="btn btn-default" href="{% url 'treasury:invoice' %}">{% trans "Invoices list" %}</a></p>
|
2020-03-21 17:59:13 +00:00
|
|
|
<form method="post" action="">
|
2020-03-21 15:49:18 +00:00
|
|
|
{% csrf_token %}
|
|
|
|
{% crispy form %}
|
|
|
|
{{ formset.management_form }}
|
|
|
|
<table class="table table-condensed table-striped">
|
|
|
|
{% for form in formset %}
|
|
|
|
{% 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" >
|
|
|
|
{% endif %}
|
|
|
|
<tr class="row-formset">
|
|
|
|
<td>{{ form.designation }}</td>
|
|
|
|
<td>{{ form.quantity }} </td>
|
2020-03-21 17:59:13 +00:00
|
|
|
<td>
|
|
|
|
<div class="input-group">
|
|
|
|
<input type="number" name="product_set-{{ forloop.counter0 }}-amount" min="0" step="0.01"
|
|
|
|
id="id_product_set-{{ forloop.counter0 }}-amount"
|
|
|
|
value="{{ form.instance.amount|cents_to_euros }}">
|
|
|
|
<div class="input-group-append">
|
|
|
|
<span class="input-group-text">€</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</td>
|
2020-03-22 00:22:27 +00:00
|
|
|
{{ form.invoice }}
|
2020-03-21 15:49:18 +00:00
|
|
|
{{ form.id }}
|
|
|
|
</tr>
|
|
|
|
{% endfor %}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<div class="btn-group btn-block" role="group">
|
|
|
|
<button type="button" id="add_more" class="btn btn-primary">{% trans "Add product" %}</button>
|
|
|
|
<button type="button" id="remove_one" class="btn btn-danger">{% trans "Remove product" %}</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="btn-block">
|
|
|
|
<button type="submit" class="btn btn-block btn-primary">{% trans "Submit" %}</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<div id="empty_form" style="display: none;">
|
|
|
|
<table class='no_error'>
|
|
|
|
<tbody id="for_real">
|
|
|
|
<tr class="row-formset">
|
|
|
|
<td>{{ formset.empty_form.designation }}</td>
|
|
|
|
<td>{{ formset.empty_form.quantity }} </td>
|
2020-03-21 17:59:13 +00:00
|
|
|
<td>
|
|
|
|
<div class="input-group">
|
|
|
|
<input type="number" name="product_set-__prefix__-amount" min="0" step="0.01"
|
|
|
|
id="id_product_set-__prefix__-amount">
|
|
|
|
<div class="input-group-append">
|
|
|
|
<span class="input-group-text">€</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</td>
|
2020-03-22 00:22:27 +00:00
|
|
|
{{ formset.empty_form.invoice }}
|
2020-03-21 15:49:18 +00:00
|
|
|
{{ formset.empty_form.id }}
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block extrajavascript %}
|
|
|
|
<script src="{% static 'js/dynamic-formset.js' %}"></script>
|
|
|
|
<script>
|
|
|
|
IDS = {};
|
|
|
|
|
|
|
|
$("#id_product_set-TOTAL_FORMS").val($(".row-formset").length - 1);
|
|
|
|
|
|
|
|
$('#add_more').click(function() {
|
|
|
|
var form_idx = $('#id_product_set-TOTAL_FORMS').val();
|
|
|
|
$('#form_body').append($('#for_real').html().replace(/__prefix__/g, form_idx));
|
|
|
|
$('#id_product_set-TOTAL_FORMS').val(parseInt(form_idx) + 1);
|
|
|
|
$('#id_product_set-' + parseInt(form_idx) + '-id').val(IDS[parseInt(form_idx)]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#remove_one').click(function() {
|
|
|
|
let form_idx = $('#id_product_set-TOTAL_FORMS').val();
|
|
|
|
if (form_idx > 0) {
|
|
|
|
IDS[parseInt(form_idx) - 1] = $('#id_product_set-' + (parseInt(form_idx) - 1) + '-id').val();
|
|
|
|
$('#form_body tr:last-child').remove();
|
|
|
|
$('#id_product_set-TOTAL_FORMS').val(parseInt(form_idx) - 1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2020-03-20 23:52:26 +00:00
|
|
|
{% endblock %}
|