forked from DGNum/gestioCOF
Suppression d'article
On fait pareil que précédemment pour les articles, en rajoutant une vie de délétion + de quoi afficher qu'un article a été supprimé. N.B. : le formatage automatique de VSCode fait plein de changements, donc pourquoi pas les garder.
This commit is contained in:
parent
123e2b84df
commit
65dd7e5fa3
4 changed files with 109 additions and 61 deletions
|
@ -30,7 +30,7 @@ function KHistory(options={}) {
|
|||
|
||||
if (ope['type'] == 'purchase') {
|
||||
infos1 = ope['article_nb'];
|
||||
infos2 = ope['article__name'];
|
||||
infos2 = ope['article__name'] ? ope['article__name'] : 'Article supprimé';
|
||||
} else {
|
||||
infos1 = parsed_amount.toFixed(2) + '€';
|
||||
switch (ope['type']) {
|
||||
|
|
|
@ -20,12 +20,21 @@
|
|||
<a class="btn btn-default" href="{% url 'kfet.article.update' article.pk %}">
|
||||
<span class="glyphicon glyphicon-cog"></span><span>Éditer</span>
|
||||
</a>
|
||||
{% if perms.kfet.delete_account %}
|
||||
<button class="btn btn-default" id="button-delete">
|
||||
<span class="glyphicon glyphicon-remove"></span><span>Supprimer</span>
|
||||
</button>
|
||||
<form method="post" action="{% url 'kfet.article.delete' article.pk %}" id="article-delete-form">
|
||||
{% csrf_token %}
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="text">
|
||||
<ul class="list-unstyled">
|
||||
<li>
|
||||
<b>Prix:</b> <span>{{ article.price }}€</span>
|
||||
<span data-toggle="tooltip" data-placement="right" class="glyphicon glyphicon-question-sign" title="Hors réduction COF"></span>
|
||||
<span data-toggle="tooltip" data-placement="right" class="glyphicon glyphicon-question-sign"
|
||||
title="Hors réduction COF"></span>
|
||||
</li>
|
||||
<li><b>Stock:</b> {{ article.stock }}</li>
|
||||
<li><b>En vente:</b> {{ article.is_sold|yesno|title }}</li>
|
||||
|
@ -129,6 +138,25 @@ $(document).ready(function() {
|
|||
tabs_buttons.removeClass('focus');
|
||||
$(this).addClass('focus');
|
||||
});
|
||||
|
||||
// Delete button
|
||||
$('#button-delete').click(function () {
|
||||
$.confirm({
|
||||
title: 'Confirmer la suppression',
|
||||
content: `
|
||||
<div class="warning">
|
||||
<span class='glyphicon glyphicon-warning-sign'></span><span>Cette opération est irréversible !</span>
|
||||
</div>
|
||||
`,
|
||||
backgroundDismiss: true,
|
||||
animation: 'top',
|
||||
closeAnimation: 'bottom',
|
||||
keyboardEnabled: true,
|
||||
confirm: function () {
|
||||
$('#article-delete-form').submit();
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
@ -186,6 +186,12 @@ urlpatterns = [
|
|||
teamkfet_required(views.ArticleUpdate.as_view()),
|
||||
name="kfet.article.update",
|
||||
),
|
||||
# Article - Delete
|
||||
path(
|
||||
"articles/<int:pk>/delete",
|
||||
views.ArticleDelete.as_view(),
|
||||
name="kfet.article.delete",
|
||||
),
|
||||
# Article - Statistics
|
||||
path(
|
||||
"articles/<int:pk>/stat/sales/list",
|
||||
|
|
|
@ -877,6 +877,20 @@ class ArticleUpdate(SuccessMessageMixin, UpdateView):
|
|||
return super().form_valid(form)
|
||||
|
||||
|
||||
class ArticleDelete(PermissionRequiredMixin, DeleteView):
|
||||
model = Article
|
||||
success_url = reverse_lazy("kfet.article")
|
||||
success_message = "Article supprimé avec succès !"
|
||||
permission_required = "kfet.delete_article"
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
return redirect("kfet.article.read", self.kwargs.get(self.pk_url_kwarg))
|
||||
|
||||
def delete(self, request, *args, **kwargs):
|
||||
messages.success(request, self.success_message)
|
||||
return super().delete(request, *args, **kwargs)
|
||||
|
||||
|
||||
# -----
|
||||
# K-Psul
|
||||
# -----
|
||||
|
|
Loading…
Reference in a new issue