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
|
@ -1,28 +1,28 @@
|
||||||
function KHistory(options={}) {
|
function KHistory(options = {}) {
|
||||||
$.extend(this, KHistory.default_options, options);
|
$.extend(this, KHistory.default_options, options);
|
||||||
|
|
||||||
this.$container = $(this.container);
|
this.$container = $(this.container);
|
||||||
|
|
||||||
this.reset = function() {
|
this.reset = function () {
|
||||||
this.$container.html('');
|
this.$container.html('');
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addOpeGroup = function(opegroup) {
|
this.addOpeGroup = function (opegroup) {
|
||||||
var $day = this._getOrCreateDay(opegroup['at']);
|
var $day = this._getOrCreateDay(opegroup['at']);
|
||||||
var $opegroup = this._opeGroupHtml(opegroup);
|
var $opegroup = this._opeGroupHtml(opegroup);
|
||||||
|
|
||||||
$day.after($opegroup);
|
$day.after($opegroup);
|
||||||
|
|
||||||
var trigramme = opegroup['on_acc_trigramme'];
|
var trigramme = opegroup['on_acc_trigramme'];
|
||||||
var is_cof = opegroup['is_cof'];
|
var is_cof = opegroup['is_cof'];
|
||||||
for (var i=0; i<opegroup['opes'].length; i++) {
|
for (var i = 0; i < opegroup['opes'].length; i++) {
|
||||||
var $ope = this._opeHtml(opegroup['opes'][i], is_cof, trigramme);
|
var $ope = this._opeHtml(opegroup['opes'][i], is_cof, trigramme);
|
||||||
$ope.data('opegroup', opegroup['id']);
|
$ope.data('opegroup', opegroup['id']);
|
||||||
$opegroup.after($ope);
|
$opegroup.after($ope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._opeHtml = function(ope, is_cof, trigramme) {
|
this._opeHtml = function (ope, is_cof, trigramme) {
|
||||||
var $ope_html = $(this.template_ope);
|
var $ope_html = $(this.template_ope);
|
||||||
var parsed_amount = parseFloat(ope['amount']);
|
var parsed_amount = parseFloat(ope['amount']);
|
||||||
var amount = amountDisplay(parsed_amount, is_cof, trigramme);
|
var amount = amountDisplay(parsed_amount, is_cof, trigramme);
|
||||||
|
@ -30,9 +30,9 @@ function KHistory(options={}) {
|
||||||
|
|
||||||
if (ope['type'] == 'purchase') {
|
if (ope['type'] == 'purchase') {
|
||||||
infos1 = ope['article_nb'];
|
infos1 = ope['article_nb'];
|
||||||
infos2 = ope['article__name'];
|
infos2 = ope['article__name'] ? ope['article__name'] : 'Article supprimé';
|
||||||
} else {
|
} else {
|
||||||
infos1 = parsed_amount.toFixed(2)+'€';
|
infos1 = parsed_amount.toFixed(2) + '€';
|
||||||
switch (ope['type']) {
|
switch (ope['type']) {
|
||||||
case 'initial':
|
case 'initial':
|
||||||
infos2 = 'Initial';
|
infos2 = 'Initial';
|
||||||
|
@ -58,7 +58,7 @@ function KHistory(options={}) {
|
||||||
var addcost_for = ope['addcost_for__trigramme'];
|
var addcost_for = ope['addcost_for__trigramme'];
|
||||||
if (addcost_for) {
|
if (addcost_for) {
|
||||||
var addcost_amount = parseFloat(ope['addcost_amount']);
|
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'])
|
if (ope['canceled_at'])
|
||||||
|
@ -67,26 +67,26 @@ function KHistory(options={}) {
|
||||||
return $ope_html;
|
return $ope_html;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cancelOpe = function(ope, $ope = null) {
|
this.cancelOpe = function (ope, $ope = null) {
|
||||||
if (!$ope)
|
if (!$ope)
|
||||||
$ope = this.findOpe(ope['id']);
|
$ope = this.findOpe(ope['id']);
|
||||||
|
|
||||||
var cancel = 'Annulé';
|
var cancel = 'Annulé';
|
||||||
var canceled_at = dateUTCToParis(ope['canceled_at']);
|
var canceled_at = dateUTCToParis(ope['canceled_at']);
|
||||||
if (ope['canceled_by__trigramme'])
|
if (ope['canceled_by__trigramme'])
|
||||||
cancel += ' par '+ope['canceled_by__trigramme'];
|
cancel += ' par ' + ope['canceled_by__trigramme'];
|
||||||
cancel += ' le '+canceled_at.format('DD/MM/YY à HH:mm:ss');
|
cancel += ' le ' + canceled_at.format('DD/MM/YY à HH:mm:ss');
|
||||||
|
|
||||||
$ope.addClass('canceled').find('.canceled').text(cancel);
|
$ope.addClass('canceled').find('.canceled').text(cancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._opeGroupHtml = function(opegroup) {
|
this._opeGroupHtml = function (opegroup) {
|
||||||
var $opegroup_html = $(this.template_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 trigramme = opegroup['on_acc__trigramme'];
|
||||||
var amount = amountDisplay(
|
var amount = amountDisplay(
|
||||||
parseFloat(opegroup['amount']), opegroup['is_cof'], trigramme);
|
parseFloat(opegroup['amount']), opegroup['is_cof'], trigramme);
|
||||||
var comment = opegroup['comment'] || '';
|
var comment = opegroup['comment'] || '';
|
||||||
|
|
||||||
$opegroup_html
|
$opegroup_html
|
||||||
|
@ -100,15 +100,15 @@ function KHistory(options={}) {
|
||||||
$opegroup_html.find('.trigramme').remove();
|
$opegroup_html.find('.trigramme').remove();
|
||||||
|
|
||||||
if (opegroup['valid_by__trigramme'])
|
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;
|
return $opegroup_html;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._getOrCreateDay = function(date) {
|
this._getOrCreateDay = function (date) {
|
||||||
var at = dateUTCToParis(date);
|
var at = dateUTCToParis(date);
|
||||||
var at_ser = at.format('YYYY-MM-DD');
|
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
|
return $(this).data('date') == at_ser
|
||||||
});
|
});
|
||||||
if ($day.length == 1)
|
if ($day.length == 1)
|
||||||
|
@ -117,23 +117,23 @@ function KHistory(options={}) {
|
||||||
return $day.data('date', at_ser).text(at.format('D MMMM'));
|
return $day.data('date', at_ser).text(at.format('D MMMM'));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.findOpeGroup = function(id) {
|
this.findOpeGroup = function (id) {
|
||||||
return this.$container.find('.opegroup').filter(function() {
|
return this.$container.find('.opegroup').filter(function () {
|
||||||
return $(this).data('opegroup') == id
|
return $(this).data('opegroup') == id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.findOpe = function(id) {
|
this.findOpe = function (id) {
|
||||||
return this.$container.find('.ope').filter(function() {
|
return this.$container.find('.ope').filter(function () {
|
||||||
return $(this).data('ope') == id
|
return $(this).data('ope') == id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cancelOpeGroup = function(opegroup) {
|
this.cancelOpeGroup = function (opegroup) {
|
||||||
var $opegroup = this.findOpeGroup(opegroup['id']);
|
var $opegroup = this.findOpeGroup(opegroup['id']);
|
||||||
var trigramme = $opegroup.find('.trigramme').text();
|
var trigramme = $opegroup.find('.trigramme').text();
|
||||||
var amount = amountDisplay(
|
var amount = amountDisplay(
|
||||||
parseFloat(opegroup['amount'], opegroup['is_cof'], trigramme));
|
parseFloat(opegroup['amount'], opegroup['is_cof'], trigramme));
|
||||||
$opegroup.find('.amount').text(amount);
|
$opegroup.find('.amount').text(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,21 @@
|
||||||
<a class="btn btn-default" href="{% url 'kfet.article.update' article.pk %}">
|
<a class="btn btn-default" href="{% url 'kfet.article.update' article.pk %}">
|
||||||
<span class="glyphicon glyphicon-cog"></span><span>Éditer</span>
|
<span class="glyphicon glyphicon-cog"></span><span>Éditer</span>
|
||||||
</a>
|
</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>
|
||||||
<div class="text">
|
<div class="text">
|
||||||
<ul class="list-unstyled">
|
<ul class="list-unstyled">
|
||||||
<li>
|
<li>
|
||||||
<b>Prix:</b> <span>{{ article.price }}€</span>
|
<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>
|
||||||
<li><b>Stock:</b> {{ article.stock }}</li>
|
<li><b>Stock:</b> {{ article.stock }}</li>
|
||||||
<li><b>En vente:</b> {{ article.is_sold|yesno|title }}</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">
|
<div id="tab_summary" class="tab-pane fade in active">
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<div>
|
<div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
|
|
||||||
<h3>Inventaires récents</h3>
|
<h3>Inventaires récents</h3>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
{% include "kfet/article_inventories_snippet.html" with inventoryarts=inventoryarts|slice:5 %}
|
{% include "kfet/article_inventories_snippet.html" with inventoryarts=inventoryarts|slice:5 %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div><!-- col -->
|
</div><!-- col -->
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
|
|
||||||
<h3>Derniers prix fournisseurs</h3>
|
<h3>Derniers prix fournisseurs</h3>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
{% include "kfet/article_suppliers_snippet.html" with supplierarts=supplierarts|slice:5 %}
|
{% include "kfet/article_suppliers_snippet.html" with supplierarts=supplierarts|slice:5 %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div><!-- col -->
|
</div><!-- col -->
|
||||||
</div><!-- row -->
|
</div><!-- row -->
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<div>
|
<div>
|
||||||
<h3>Ventes</h3>
|
<h3>Ventes</h3>
|
||||||
<div id="stat_last"></div>
|
<div id="stat_last"></div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</div><!-- summary tab -->
|
</div><!-- summary tab -->
|
||||||
|
|
||||||
|
@ -110,26 +119,45 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function () {
|
||||||
var stat_last = new StatsGroup(
|
var stat_last = new StatsGroup(
|
||||||
"{% url 'kfet.article.stat.sales.list' article.id %}",
|
"{% url 'kfet.article.stat.sales.list' article.id %}",
|
||||||
$("#stat_last")
|
$("#stat_last")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
|
|
||||||
$("table .more").click( function() {
|
$("table .more").click(function () {
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
$(this).siblings(".hidden").removeClass("hidden");
|
$(this).siblings(".hidden").removeClass("hidden");
|
||||||
});
|
});
|
||||||
|
|
||||||
let tabs_buttons = $('.tabs-buttons a');
|
let tabs_buttons = $('.tabs-buttons a');
|
||||||
tabs_buttons.click( function() {
|
tabs_buttons.click(function () {
|
||||||
tabs_buttons.removeClass('focus');
|
tabs_buttons.removeClass('focus');
|
||||||
$(this).addClass('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>
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -186,6 +186,12 @@ urlpatterns = [
|
||||||
teamkfet_required(views.ArticleUpdate.as_view()),
|
teamkfet_required(views.ArticleUpdate.as_view()),
|
||||||
name="kfet.article.update",
|
name="kfet.article.update",
|
||||||
),
|
),
|
||||||
|
# Article - Delete
|
||||||
|
path(
|
||||||
|
"articles/<int:pk>/delete",
|
||||||
|
views.ArticleDelete.as_view(),
|
||||||
|
name="kfet.article.delete",
|
||||||
|
),
|
||||||
# Article - Statistics
|
# Article - Statistics
|
||||||
path(
|
path(
|
||||||
"articles/<int:pk>/stat/sales/list",
|
"articles/<int:pk>/stat/sales/list",
|
||||||
|
|
|
@ -877,6 +877,20 @@ class ArticleUpdate(SuccessMessageMixin, UpdateView):
|
||||||
return super().form_valid(form)
|
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
|
# K-Psul
|
||||||
# -----
|
# -----
|
||||||
|
|
Loading…
Reference in a new issue