Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions barsys/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.utils.translation import ugettext_lazy as _

from .models import *
from pybarsys.settings import PybarsysPreferences


class LoginForm(auth_forms.AuthenticationForm):
Expand Down Expand Up @@ -93,24 +94,25 @@ class InvoicesCreateForm(forms.Form):

send_invoices = forms.BooleanField(required=False, initial=True,
help_text="Whether to send invoice mails to the users' mail addresses. "
"Users who do not pay for themselves will get a notification of their "
"purchases instead of a real invoice. If an error occurs during "
"sending, new invoices may be deleted again automatically."
"If an error occurs during mail transmission, "
"no invoice will be created."
"If false, invoices will only be created internally.")

send_dependant_notifications = forms.BooleanField(required=False, initial=True,
help_text="Whether to send purchase notifications to users who do"
" not pay themselves (only valid if invoices are sent "
"at all).")
" not pay themselves (only valid if invoice mails are "
"sent at all).")

send_payment_reminders = forms.BooleanField(required=False, initial=True,
help_text="Whether to send payment reminder mails to users with an "
"account balance below number defined in settings, but "
"no unbilled purchases.")
"no unbilled purchases (only valid if invoice mails are "
"sent at all).")

autolock_accounts = forms.BooleanField(required=False, initial=True,
help_text="Automatically lock account if balance is below "
"number defined in settings before and after creating new invoices.")
"{} before and after creating new invoices.".format(
currency(PybarsysPreferences.Misc.BALANCE_BELOW_AUTOLOCK)))

comment = forms.CharField(label="Comment", required=False)

Expand Down Expand Up @@ -326,6 +328,10 @@ class Meta:
model = Payment
exclude = ('invoice',)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['user'].queryset = User.objects.filter(purchases_paid_by_other__isnull=True)


class FreeItemForm(forms.ModelForm):
class Meta:
Expand Down
7 changes: 6 additions & 1 deletion barsys/templates/barsys/admin/invoice_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ <h1 class="pull-left" style="margin-top: 0;">Invoice details</h1>
</tbody>
</table>
</div>
{% endblock %}
<p class="text-right">
<a href="{% url 'admin_invoice_mail' invoice.pk %}" class="btn btn-default btn-xs" target="_blank">
{% bootstrap_icon 'new-window' %} Open mail preview
</a>
</p>
{% endblock %}
17 changes: 17 additions & 0 deletions barsys/templates/barsys/admin/invoice_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,21 @@

<h1>Create invoices</h1>
{% crispy form %}
<script>
(function () {
var select = document.getElementById('id_users');
var input = document.createElement('input');
input.type = 'text';
input.placeholder = 'Filter by user name';
input.className = 'form-control';
input.style.marginBottom = '4px';
select.parentNode.insertBefore(input, select);
input.addEventListener('keyup', function () {
var q = input.value.toLowerCase();
Array.from(select.options).forEach(function (opt) {
opt.style.display = opt.text.toLowerCase().includes(q) ? '' : 'none';
});
});
})();
</script>
{% endblock %}
6 changes: 5 additions & 1 deletion barsys/templates/barsys/admin/payment_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ <h1 class="pull-left" style="margin-top: 0;">Payment details</h1>

</tbody>
</table>
{% endblock %}

<a href="{% url 'admin_invoice_new' %}?user={{ object.user_id }}" class="btn btn-primary btn-lg btn-block">
{% bootstrap_icon 'file' %} Generate invoice for {{ object.user }}
</a>
{% endblock %}
14 changes: 13 additions & 1 deletion barsys/templates/barsys/admin/user_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
<div>
<h1 class="pull-left" style="margin-top: 0;">User details</h1>
<div class="btn-group pull-right" role="group">
{% if object.pays_themselves %}
<a href="{% url 'admin_invoice_new' %}?user={{ object.pk }}" class="btn btn-default">
{% bootstrap_icon 'file' %} Create invoice
</a>
{% endif %}
{% if object.account_balance < 0 %}
<a href="{% url 'admin_user_payment_reminder_send' object.pk %}" class="btn btn-warning">
{% bootstrap_icon 'warning-sign' %} Send payment reminder
</a>
{% endif %}
<a href="{% url 'admin_user_update' object.pk %}" class="btn btn-primary">
{% bootstrap_icon 'pencil' %} Change
</a>
Expand Down Expand Up @@ -124,4 +131,9 @@ <h1 class="pull-left" style="margin-top: 0;">Invoices</h1>

<p>{{ invoices_page_obj.paginator.count }} result(s)</p>
{% bootstrap_pagination invoices_page_obj extra=request.GET.urlencode parameter_name="invoices_page" %}
{% endblock %}
<p class="text-right">
<a href="{% url 'admin_user_payment_reminder_mail' object.pk %}" class="btn btn-default btn-xs" target="_blank">
{% bootstrap_icon 'new-window' %} Open payment reminder preview
</a>
</p>
{% endblock %}
Loading
Loading