forked from DGNum/gestioCOF
Pas besoin de ws pour les suppressions
This commit is contained in:
parent
550a073d51
commit
49ef8b3c15
3 changed files with 41 additions and 47 deletions
|
@ -35,14 +35,14 @@ function KHistory(options = {}) {
|
|||
var is_cof = opegroup['is_cof'];
|
||||
var type = opegroup['type']
|
||||
switch (type) {
|
||||
case 'opegroup':
|
||||
case 'operation':
|
||||
for (let ope of opegroup['opes']) {
|
||||
var $ope = this._opeHtml(ope, is_cof, trigramme);
|
||||
$ope.data('opegroup', opegroup['id']);
|
||||
$opegroup.after($ope);
|
||||
}
|
||||
break;
|
||||
case 'transfergroup':
|
||||
case 'transfer':
|
||||
for (let transfer of opegroup['opes']) {
|
||||
var $transfer = this._transferHtml(transfer);
|
||||
$transfer.data('transfergroup', opegroup['id']);
|
||||
|
@ -80,7 +80,7 @@ function KHistory(options = {}) {
|
|||
}
|
||||
|
||||
$ope_html
|
||||
.data('type', 'ope')
|
||||
.data('type', 'operation')
|
||||
.data('id', ope['id'])
|
||||
.find('.amount').text(amount).end()
|
||||
.find('.infos1').text(infos1).end()
|
||||
|
@ -119,7 +119,7 @@ function KHistory(options = {}) {
|
|||
|
||||
this.cancelOpe = function (ope, $ope = null) {
|
||||
if (!$ope)
|
||||
$ope = this.findOpe(ope['id'], ope["type"]);
|
||||
$ope = this.findOpe(ope["id"], ope["type"]);
|
||||
|
||||
var cancel = 'Annulé';
|
||||
var canceled_at = dateUTCToParis(ope['canceled_at']);
|
||||
|
@ -135,13 +135,13 @@ function KHistory(options = {}) {
|
|||
|
||||
|
||||
switch (type) {
|
||||
case 'opegroup':
|
||||
case 'operation':
|
||||
var $opegroup_html = $(this.template_opegroup);
|
||||
var trigramme = opegroup['on_acc__trigramme'];
|
||||
var amount = amountDisplay(
|
||||
parseFloat(opegroup['amount']), opegroup['is_cof'], trigramme);
|
||||
break;
|
||||
case 'transfergroup':
|
||||
case 'transfer':
|
||||
var $opegroup_html = $(this.template_transfergroup);
|
||||
$opegroup_html.find('.infos').text('Transferts').end()
|
||||
var trigramme = '';
|
||||
|
@ -183,20 +183,20 @@ function KHistory(options = {}) {
|
|||
return $day.data('date', at_ser).text(at.format('D MMMM YYYY'));
|
||||
}
|
||||
|
||||
this.findOpeGroup = function (id) {
|
||||
this.findOpeGroup = function (id, type = "operation") {
|
||||
return this.$container.find('.opegroup').filter(function () {
|
||||
return $(this).data('opegroup') == id
|
||||
return ($(this).data('id') == id && $(this).data("type") == type)
|
||||
});
|
||||
}
|
||||
|
||||
this.findOpe = function (id, type = 'ope') {
|
||||
this.findOpe = function (id, type = 'operation') {
|
||||
return this.$container.find('.ope').filter(function () {
|
||||
return ($(this).data('id') == id && $(this).data('type') == type)
|
||||
});
|
||||
}
|
||||
|
||||
this.cancelOpeGroup = function (opegroup) {
|
||||
var $opegroup = this.findOpeGroup(opegroup['id']);
|
||||
this.update_opegroup = function (opegroup, type = "operation") {
|
||||
var $opegroup = this.findOpeGroup(opegroup['id'], type);
|
||||
var trigramme = $opegroup.find('.trigramme').text();
|
||||
var amount = amountDisplay(
|
||||
parseFloat(opegroup['amount']), opegroup['is_cof'], trigramme);
|
||||
|
@ -218,13 +218,14 @@ function KHistory(options = {}) {
|
|||
});
|
||||
}
|
||||
|
||||
this.cancel = function (type, opes, password = "") {
|
||||
this._cancel = function (type, opes, password = "") {
|
||||
if (window.lock == 1)
|
||||
return false
|
||||
window.lock = 1;
|
||||
var that = this;
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: django_urls[`kfet.${type}.cancel`](),
|
||||
url: django_urls[`kfet.${type}s.cancel`](),
|
||||
method: "POST",
|
||||
data: opes,
|
||||
beforeSend: function ($xhr) {
|
||||
|
@ -235,6 +236,16 @@ function KHistory(options = {}) {
|
|||
|
||||
}).done(function (data) {
|
||||
window.lock = 0;
|
||||
that.$container.find('.ui-selected').removeClass('ui-selected');
|
||||
for (let ope of data["canceled"]) {
|
||||
ope["type"] = type;
|
||||
that.cancelOpe(ope);
|
||||
}
|
||||
if (type == "operation") {
|
||||
for (let opegroup of data["opegroups_to_update"]) {
|
||||
that.update_opegroup(opegroup)
|
||||
}
|
||||
}
|
||||
}).fail(function ($xhr) {
|
||||
var data = $xhr.responseJSON;
|
||||
switch ($xhr.status) {
|
||||
|
@ -274,10 +285,10 @@ function KHistory(options = {}) {
|
|||
});
|
||||
} else if (opes_to_cancel["transfers"].length > 0) {
|
||||
delete opes_to_cancel["operations"];
|
||||
this.cancel("transfers", opes_to_cancel);
|
||||
this._cancel("transfer", opes_to_cancel);
|
||||
} else if (opes_to_cancel["operations"].length > 0) {
|
||||
delete opes_to_cancel["transfers"];
|
||||
this.cancel("operations", opes_to_cancel);
|
||||
this._cancel("operation", opes_to_cancel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1256,13 +1256,6 @@ $(document).ready(function() {
|
|||
for (var i=0; i<data['opegroups'].length; i++) {
|
||||
if (data['opegroups'][i]['add']) {
|
||||
khistory.addOpeGroup(data['opegroups'][i]);
|
||||
} else if (data['opegroups'][i]['cancellation']) {
|
||||
khistory.cancelOpeGroup(data['opegroups'][i]);
|
||||
}
|
||||
}
|
||||
for (var i=0; i<data['opes'].length; i++) {
|
||||
if (data['opes'][i]['cancellation']) {
|
||||
khistory.cancelOpe(data['opes'][i]);
|
||||
}
|
||||
}
|
||||
for (var i=0; i<data['checkouts'].length; i++) {
|
||||
|
|
|
@ -1364,7 +1364,11 @@ def cancel_operations(request):
|
|||
.filter(pk__in=opegroups_pk)
|
||||
.order_by("pk")
|
||||
)
|
||||
opes = sorted(opes)
|
||||
opes = (
|
||||
Operation.objects.values("id", "canceled_at", "canceled_by__trigramme")
|
||||
.filter(pk__in=opes)
|
||||
.order_by("pk")
|
||||
)
|
||||
checkouts_pk = [checkout.pk for checkout in to_checkouts_balances]
|
||||
checkouts = (
|
||||
Checkout.objects.values("id", "balance")
|
||||
|
@ -1375,27 +1379,7 @@ def cancel_operations(request):
|
|||
articles = Article.objects.values("id", "stock").filter(pk__in=articles_pk)
|
||||
|
||||
# Websocket data
|
||||
websocket_data = {"opegroups": [], "opes": [], "checkouts": [], "articles": []}
|
||||
|
||||
for opegroup in opegroups:
|
||||
websocket_data["opegroups"].append(
|
||||
{
|
||||
"cancellation": True,
|
||||
"id": opegroup["id"],
|
||||
"amount": opegroup["amount"],
|
||||
"is_cof": opegroup["is_cof"],
|
||||
}
|
||||
)
|
||||
canceled_by__trigramme = canceled_by and canceled_by.trigramme or None
|
||||
for ope in opes:
|
||||
websocket_data["opes"].append(
|
||||
{
|
||||
"cancellation": True,
|
||||
"id": ope,
|
||||
"canceled_by__trigramme": canceled_by__trigramme,
|
||||
"canceled_at": canceled_at,
|
||||
}
|
||||
)
|
||||
websocket_data = {"checkouts": [], "articles": []}
|
||||
for checkout in checkouts:
|
||||
websocket_data["checkouts"].append(
|
||||
{"id": checkout["id"], "balance": checkout["balance"]}
|
||||
|
@ -1406,7 +1390,8 @@ def cancel_operations(request):
|
|||
)
|
||||
consumers.KPsul.group_send("kfet.kpsul", websocket_data)
|
||||
|
||||
data["canceled"] = opes
|
||||
data["canceled"] = list(opes)
|
||||
data["opegroups_to_update"] = list(opegroups)
|
||||
if opes_already_canceled:
|
||||
data["warnings"]["already_canceled"] = opes_already_canceled
|
||||
return JsonResponse(data)
|
||||
|
@ -1483,7 +1468,7 @@ def history_json(request):
|
|||
opegroups_list = []
|
||||
for opegroup in opegroups:
|
||||
opegroup_dict = {
|
||||
"type": "opegroup",
|
||||
"type": "operation",
|
||||
"id": opegroup.id,
|
||||
"amount": opegroup.amount,
|
||||
"at": opegroup.at,
|
||||
|
@ -1519,7 +1504,7 @@ def history_json(request):
|
|||
for transfergroup in transfergroups:
|
||||
if transfergroup.filtered_transfers:
|
||||
transfergroup_dict = {
|
||||
"type": "transfergroup",
|
||||
"type": "transfer",
|
||||
"id": transfergroup.id,
|
||||
"at": transfergroup.at,
|
||||
"comment": transfergroup.comment,
|
||||
|
@ -1809,6 +1794,11 @@ def cancel_transfers(request):
|
|||
elif hasattr(account, "negative") and not account.negative.balance_offset:
|
||||
account.negative.delete()
|
||||
|
||||
transfers = (
|
||||
Transfer.objects.values("id", "canceled_at", "canceled_by__trigramme")
|
||||
.filter(pk__in=transfers)
|
||||
.order_by("pk")
|
||||
)
|
||||
data["canceled"] = transfers
|
||||
if transfers_already_canceled:
|
||||
data["warnings"]["already_canceled"] = transfers_already_canceled
|
||||
|
|
Loading…
Reference in a new issue