mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-11-26 18:37:12 +00:00
Button create a transaction through the API
This commit is contained in:
parent
7f432f5bc5
commit
cebbe65eef
@ -18,6 +18,7 @@ class HistoryTable(tables.Table):
|
|||||||
}
|
}
|
||||||
model = Transaction
|
model = Transaction
|
||||||
exclude = ("polymorphic_ctype", )
|
exclude = ("polymorphic_ctype", )
|
||||||
|
order_by = ('-created_at', )
|
||||||
template_name = 'django_tables2/bootstrap4.html'
|
template_name = 'django_tables2/bootstrap4.html'
|
||||||
sequence = ('...', 'total', 'valid')
|
sequence = ('...', 'total', 'valid')
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from dal import autocomplete
|
from dal import autocomplete
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
@ -10,7 +11,7 @@ from django.views.generic import CreateView, ListView, UpdateView
|
|||||||
from django_tables2 import SingleTableView
|
from django_tables2 import SingleTableView
|
||||||
|
|
||||||
from .forms import TransactionForm, TransactionTemplateForm
|
from .forms import TransactionForm, TransactionTemplateForm
|
||||||
from .models import Transaction, TransactionTemplate, Alias
|
from .models import Transaction, TransactionTemplate, Alias, TemplateTransaction
|
||||||
from .tables import HistoryTable
|
from .tables import HistoryTable
|
||||||
|
|
||||||
|
|
||||||
@ -142,6 +143,7 @@ class ConsoView(LoginRequiredMixin, SingleTableView):
|
|||||||
context['transaction_templates'] = TransactionTemplate.objects.filter(display=True) \
|
context['transaction_templates'] = TransactionTemplate.objects.filter(display=True) \
|
||||||
.order_by('category')
|
.order_by('category')
|
||||||
context['title'] = _("Consumptions")
|
context['title'] = _("Consumptions")
|
||||||
|
context['polymorphic_ctype'] = ContentType.objects.get_for_model(TemplateTransaction).pk
|
||||||
|
|
||||||
# select2 compatibility
|
# select2 compatibility
|
||||||
context['no_cache'] = True
|
context['no_cache'] = True
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
<img src="https://perso.crans.org/erdnaxe/site-crans/img/logo.svg"
|
<img src="https://perso.crans.org/erdnaxe/site-crans/img/logo.svg"
|
||||||
alt="" class="img-fluid rounded mx-auto d-block">
|
alt="" class="img-fluid rounded mx-auto d-block">
|
||||||
<div class="card-body text-center">
|
<div class="card-body text-center">
|
||||||
Paquito (aka. PAC) : -230 €
|
<span id="user_note">
|
||||||
|
Paquito (aka. PAC) : -230 €
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -82,7 +84,7 @@
|
|||||||
<div class="d-inline-flex flex-wrap justify-content-center">
|
<div class="d-inline-flex flex-wrap justify-content-center">
|
||||||
{% for button in category.list %}
|
{% for button in category.list %}
|
||||||
<button class="btn btn-outline-dark rounded-0 flex-fill"
|
<button class="btn btn-outline-dark rounded-0 flex-fill"
|
||||||
name="button" value="{{ button.name }}">
|
id="button{{ button.id }}" name="button" value="{{ button.name }}">
|
||||||
{{ button.name }} ({{ button.amount | pretty_money }})
|
{{ button.name }} ({{ button.amount | pretty_money }})
|
||||||
</button>
|
</button>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -146,6 +148,46 @@
|
|||||||
$(document.body).on("click", "a[data-toggle='tab']", function(event) {
|
$(document.body).on("click", "a[data-toggle='tab']", function(event) {
|
||||||
location.hash = this.getAttribute("href");
|
location.hash = this.getAttribute("href");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
{% for button in transaction_templates %}
|
||||||
|
$("#button{{ button.id }}").click(function() {
|
||||||
|
$.post("/api/note/transaction/transaction/",
|
||||||
|
{
|
||||||
|
"csrfmiddlewaretoken": "{{ csrf_token }}",
|
||||||
|
"quantity": 1,
|
||||||
|
"amount": {{ button.amount }},
|
||||||
|
"reason": "{{ button.name }} ({{ button.category.name }})",
|
||||||
|
"valid": true,
|
||||||
|
"polymorphic_ctype": {{ polymorphic_ctype }},
|
||||||
|
"resourcetype": "TemplateTransaction",
|
||||||
|
"source": 6,
|
||||||
|
"destination": 7,
|
||||||
|
"category": {{ button.category.id }},
|
||||||
|
"template": {{ button.id }}
|
||||||
|
},
|
||||||
|
function(data, status) {
|
||||||
|
reloadWithTurbolinks();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
{% endfor %}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var reloadWithTurbolinks = (function () {
|
||||||
|
var scrollPosition;
|
||||||
|
|
||||||
|
function reload () {
|
||||||
|
scrollPosition = [window.scrollX, window.scrollY];
|
||||||
|
Turbolinks.visit(window.location.toString(), { action: 'replace' })
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('turbolinks:load', function () {
|
||||||
|
if (scrollPosition) {
|
||||||
|
window.scrollTo.apply(window, scrollPosition);
|
||||||
|
scrollPosition = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return reload;
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user