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:
Ludovic Stephan 2019-05-24 19:32:57 +02:00
parent 123e2b84df
commit 65dd7e5fa3
4 changed files with 109 additions and 61 deletions

View file

@ -1,28 +1,28 @@
function KHistory(options={}) {
function KHistory(options = {}) {
$.extend(this, KHistory.default_options, options);
this.$container = $(this.container);
this.reset = function() {
this.reset = function () {
this.$container.html('');
};
this.addOpeGroup = function(opegroup) {
this.addOpeGroup = function (opegroup) {
var $day = this._getOrCreateDay(opegroup['at']);
var $opegroup = this._opeGroupHtml(opegroup);
$day.after($opegroup);
var trigramme = opegroup['on_acc_trigramme'];
var is_cof = opegroup['is_cof'];
for (var i=0; i<opegroup['opes'].length; i++) {
var is_cof = opegroup['is_cof'];
for (var i = 0; i < opegroup['opes'].length; i++) {
var $ope = this._opeHtml(opegroup['opes'][i], is_cof, trigramme);
$ope.data('opegroup', opegroup['id']);
$opegroup.after($ope);
}
}
this._opeHtml = function(ope, is_cof, trigramme) {
this._opeHtml = function (ope, is_cof, trigramme) {
var $ope_html = $(this.template_ope);
var parsed_amount = parseFloat(ope['amount']);
var amount = amountDisplay(parsed_amount, is_cof, trigramme);
@ -30,9 +30,9 @@ 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)+'€';
infos1 = parsed_amount.toFixed(2) + '€';
switch (ope['type']) {
case 'initial':
infos2 = 'Initial';
@ -58,7 +58,7 @@ function KHistory(options={}) {
var addcost_for = ope['addcost_for__trigramme'];
if (addcost_for) {
var addcost_amount = parseFloat(ope['addcost_amount']);
$ope_html.find('.addcost').text('('+amountDisplay(addcost_amount, is_cof)+'UKF pour '+addcost_for+')');
$ope_html.find('.addcost').text('(' + amountDisplay(addcost_amount, is_cof) + 'UKF pour ' + addcost_for + ')');
}
if (ope['canceled_at'])
@ -67,26 +67,26 @@ function KHistory(options={}) {
return $ope_html;
}
this.cancelOpe = function(ope, $ope = null) {
this.cancelOpe = function (ope, $ope = null) {
if (!$ope)
$ope = this.findOpe(ope['id']);
var cancel = 'Annulé';
var canceled_at = dateUTCToParis(ope['canceled_at']);
if (ope['canceled_by__trigramme'])
cancel += ' par '+ope['canceled_by__trigramme'];
cancel += ' le '+canceled_at.format('DD/MM/YY à HH:mm:ss');
cancel += ' par ' + ope['canceled_by__trigramme'];
cancel += ' le ' + canceled_at.format('DD/MM/YY à HH:mm:ss');
$ope.addClass('canceled').find('.canceled').text(cancel);
}
this._opeGroupHtml = function(opegroup) {
this._opeGroupHtml = function (opegroup) {
var $opegroup_html = $(this.template_opegroup);
var at = dateUTCToParis(opegroup['at']).format('HH:mm:ss');
var at = dateUTCToParis(opegroup['at']).format('HH:mm:ss');
var trigramme = opegroup['on_acc__trigramme'];
var amount = amountDisplay(
parseFloat(opegroup['amount']), opegroup['is_cof'], trigramme);
var amount = amountDisplay(
parseFloat(opegroup['amount']), opegroup['is_cof'], trigramme);
var comment = opegroup['comment'] || '';
$opegroup_html
@ -100,15 +100,15 @@ function KHistory(options={}) {
$opegroup_html.find('.trigramme').remove();
if (opegroup['valid_by__trigramme'])
$opegroup_html.find('.valid_by').text('Par '+opegroup['valid_by__trigramme']);
$opegroup_html.find('.valid_by').text('Par ' + opegroup['valid_by__trigramme']);
return $opegroup_html;
}
this._getOrCreateDay = function(date) {
this._getOrCreateDay = function (date) {
var at = dateUTCToParis(date);
var at_ser = at.format('YYYY-MM-DD');
var $day = this.$container.find('.day').filter(function() {
var $day = this.$container.find('.day').filter(function () {
return $(this).data('date') == at_ser
});
if ($day.length == 1)
@ -117,23 +117,23 @@ function KHistory(options={}) {
return $day.data('date', at_ser).text(at.format('D MMMM'));
}
this.findOpeGroup = function(id) {
return this.$container.find('.opegroup').filter(function() {
this.findOpeGroup = function (id) {
return this.$container.find('.opegroup').filter(function () {
return $(this).data('opegroup') == id
});
}
this.findOpe = function(id) {
return this.$container.find('.ope').filter(function() {
this.findOpe = function (id) {
return this.$container.find('.ope').filter(function () {
return $(this).data('ope') == id
});
}
this.cancelOpeGroup = function(opegroup) {
this.cancelOpeGroup = function (opegroup) {
var $opegroup = this.findOpeGroup(opegroup['id']);
var trigramme = $opegroup.find('.trigramme').text();
var amount = amountDisplay(
parseFloat(opegroup['amount'], opegroup['is_cof'], trigramme));
parseFloat(opegroup['amount'], opegroup['is_cof'], trigramme));
$opegroup.find('.amount').text(amount);
}

View file

@ -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>
@ -63,35 +72,35 @@
<div id="tab_summary" class="tab-pane fade in active">
<section>
<div>
<div class="row">
<div class="col-lg-6">
<section>
<div>
<div class="row">
<div class="col-lg-6">
<h3>Inventaires récents</h3>
<div class="table-responsive">
{% include "kfet/article_inventories_snippet.html" with inventoryarts=inventoryarts|slice:5 %}
</div>
<h3>Inventaires récents</h3>
<div class="table-responsive">
{% include "kfet/article_inventories_snippet.html" with inventoryarts=inventoryarts|slice:5 %}
</div>
</div><!-- col -->
<div class="col-lg-6">
</div><!-- col -->
<div class="col-lg-6">
<h3>Derniers prix fournisseurs</h3>
<div class="table-responsive">
{% include "kfet/article_suppliers_snippet.html" with supplierarts=supplierarts|slice:5 %}
</div>
<h3>Derniers prix fournisseurs</h3>
<div class="table-responsive">
{% include "kfet/article_suppliers_snippet.html" with supplierarts=supplierarts|slice:5 %}
</div>
</div><!-- col -->
</div><!-- row -->
</div>
</section>
</div><!-- col -->
</div><!-- row -->
</div>
</section>
<section>
<div>
<h3>Ventes</h3>
<div id="stat_last"></div>
</div>
</section>
<section>
<div>
<h3>Ventes</h3>
<div id="stat_last"></div>
</div>
</section>
</div><!-- summary tab -->
@ -110,26 +119,45 @@
</div>
<script type="text/javascript">
$(document).ready(function() {
$(document).ready(function () {
var stat_last = new StatsGroup(
"{% url 'kfet.article.stat.sales.list' article.id %}",
$("#stat_last")
"{% url 'kfet.article.stat.sales.list' article.id %}",
$("#stat_last")
);
$('[data-toggle="tooltip"]').tooltip();
$("table .more").click( function() {
$(this).hide();
$(this).siblings(".hidden").removeClass("hidden");
$("table .more").click(function () {
$(this).hide();
$(this).siblings(".hidden").removeClass("hidden");
});
let tabs_buttons = $('.tabs-buttons a');
tabs_buttons.click( function() {
tabs_buttons.removeClass('focus');
$(this).addClass('focus');
tabs_buttons.click(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>
{% endblock %}
{% endblock %}

View file

@ -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",

View file

@ -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
# -----