forked from DGNum/gestioCOF
Refactor js code
Harmonize history denominations * opegroups/transfergroups -> groups * opes/transfers -> entries * snake/camel case -> snake case
This commit is contained in:
parent
b450cb09e6
commit
931b2c4e1f
5 changed files with 127 additions and 135 deletions
|
@ -20,7 +20,7 @@
|
||||||
z-index:10;
|
z-index:10;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .opegroup {
|
#history .group {
|
||||||
height:30px;
|
height:30px;
|
||||||
line-height:30px;
|
line-height:30px;
|
||||||
background-color: #c63b52;
|
background-color: #c63b52;
|
||||||
|
@ -30,29 +30,29 @@
|
||||||
overflow:auto;
|
overflow:auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .opegroup .time {
|
#history .group .time {
|
||||||
width:70px;
|
width:70px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .opegroup .trigramme {
|
#history .group .trigramme {
|
||||||
width:55px;
|
width:55px;
|
||||||
text-align:right;
|
text-align:right;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .opegroup .amount {
|
#history .group .amount {
|
||||||
text-align:right;
|
text-align:right;
|
||||||
width:90px;
|
width:90px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .opegroup .valid_by {
|
#history .group .valid_by {
|
||||||
padding-left:20px
|
padding-left:20px
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .opegroup .comment {
|
#history .group .comment {
|
||||||
padding-left:20px;
|
padding-left:20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .ope {
|
#history .entry {
|
||||||
position:relative;
|
position:relative;
|
||||||
height:25px;
|
height:25px;
|
||||||
line-height:24px;
|
line-height:24px;
|
||||||
|
@ -61,38 +61,38 @@
|
||||||
overflow:auto;
|
overflow:auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .ope .amount {
|
#history .entry .amount {
|
||||||
width:50px;
|
width:50px;
|
||||||
text-align:right;
|
text-align:right;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .ope .infos1 {
|
#history .entry .infos1 {
|
||||||
width:80px;
|
width:80px;
|
||||||
text-align:right;
|
text-align:right;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .ope .infos2 {
|
#history .entry .infos2 {
|
||||||
padding-left:15px;
|
padding-left:15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .ope .addcost {
|
#history .entry .addcost {
|
||||||
padding-left:20px;
|
padding-left:20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .ope .canceled {
|
#history .entry .canceled {
|
||||||
padding-left:20px;
|
padding-left:20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history div.ope.ui-selected, #history div.ope.ui-selecting {
|
#history div.entry.ui-selected, #history div.entry.ui-selecting {
|
||||||
background-color:rgba(200,16,46,0.6);
|
background-color:rgba(200,16,46,0.6);
|
||||||
color:#FFF;
|
color:#FFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .ope.canceled, #history .transfer.canceled {
|
#history .entry.canceled {
|
||||||
color:#444;
|
color:#444;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .ope.canceled::before, #history.transfer.canceled::before {
|
#history .entry.canceled::before {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
content: ' ';
|
content: ' ';
|
||||||
width:100%;
|
width:100%;
|
||||||
|
@ -101,19 +101,11 @@
|
||||||
border-top: 1px solid rgba(200,16,46,0.5);
|
border-top: 1px solid rgba(200,16,46,0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .transfer .amount {
|
#history .group .infos {
|
||||||
width:80px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#history .transfer .from_acc {
|
|
||||||
padding-left:10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#history .opegroup .infos {
|
|
||||||
text-align:center;
|
text-align:center;
|
||||||
width:145px;
|
width:145px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#history .ope .glyphicon {
|
#history .entry .glyphicon {
|
||||||
padding-left:15px;
|
padding-left:15px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,19 +2,20 @@ function dateUTCToParis(date) {
|
||||||
return moment.tz(date, 'UTC').tz('Europe/Paris');
|
return moment.tz(date, 'UTC').tz('Europe/Paris');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO : classifier (later)
|
||||||
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.$container.selectable({
|
this.$container.selectable({
|
||||||
filter: 'div.opegroup, div.ope',
|
filter: 'div.group, div.entry',
|
||||||
selected: function (e, ui) {
|
selected: function (e, ui) {
|
||||||
$(ui.selected).each(function () {
|
$(ui.selected).each(function () {
|
||||||
if ($(this).hasClass('opegroup')) {
|
if ($(this).hasClass('group')) {
|
||||||
var opegroup = $(this).data('id');
|
var id = $(this).data('id');
|
||||||
$(this).siblings('.ope').filter(function () {
|
$(this).siblings('.entry').filter(function () {
|
||||||
return $(this).data('group') == opegroup
|
return $(this).data('group_id') == id
|
||||||
}).addClass('ui-selected');
|
}).addClass('ui-selected');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -25,36 +26,35 @@ function KHistory(options = {}) {
|
||||||
this.$container.html('');
|
this.$container.html('');
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addOpeGroup = function (opegroup) {
|
this.add_history_group = function (group) {
|
||||||
var $day = this._getOrCreateDay(opegroup['at']);
|
var $day = this._get_or_create_day(group['at']);
|
||||||
var $opegroup = this._opeGroupHtml(opegroup);
|
var $group = this._group_html(group);
|
||||||
|
|
||||||
$day.after($opegroup);
|
$day.after($group);
|
||||||
|
|
||||||
var trigramme = opegroup['on_acc_trigramme'];
|
var trigramme = group['on_acc_trigramme'];
|
||||||
var is_cof = opegroup['is_cof'];
|
var is_cof = group['is_cof'];
|
||||||
var type = opegroup['type']
|
var type = group['type']
|
||||||
|
// TODO : simplifier ça ?
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'operation':
|
case 'operation':
|
||||||
for (let ope of opegroup['opes']) {
|
for (let ope of group['entries']) {
|
||||||
var $ope = this._opeHtml(ope, is_cof, trigramme);
|
var $ope = this._ope_html(ope, is_cof, trigramme);
|
||||||
$ope.data('group', opegroup['id']);
|
$ope.data('group_id', group['id']);
|
||||||
$ope.data('group_type', type);
|
$group.after($ope);
|
||||||
$opegroup.after($ope);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'transfer':
|
case 'transfer':
|
||||||
for (let transfer of opegroup['opes']) {
|
for (let transfer of group['entries']) {
|
||||||
var $transfer = this._transferHtml(transfer);
|
var $transfer = this._transfer_html(transfer);
|
||||||
$transfer.data('group', opegroup['id']);
|
$transfer.data('group_id', group['id']);
|
||||||
$transfer.data('group_type', type);
|
$group.after($transfer);
|
||||||
$opegroup.after($transfer);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._opeHtml = function (ope, is_cof, trigramme) {
|
this._ope_html = 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);
|
||||||
|
@ -95,12 +95,12 @@ function KHistory(options = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ope['canceled_at'])
|
if (ope['canceled_at'])
|
||||||
this.cancelOpe(ope, $ope_html);
|
this.cancel_entry(ope, $ope_html);
|
||||||
|
|
||||||
return $ope_html;
|
return $ope_html;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._transferHtml = function (transfer) {
|
this._transfer_html = function (transfer) {
|
||||||
var $transfer_html = $(this.template_transfer);
|
var $transfer_html = $(this.template_transfer);
|
||||||
var parsed_amount = parseFloat(transfer['amount']);
|
var parsed_amount = parseFloat(transfer['amount']);
|
||||||
var amount = parsed_amount.toFixed(2) + '€';
|
var amount = parsed_amount.toFixed(2) + '€';
|
||||||
|
@ -113,67 +113,67 @@ function KHistory(options = {}) {
|
||||||
.find('.infos2').text(transfer['to_acc']).end();
|
.find('.infos2').text(transfer['to_acc']).end();
|
||||||
|
|
||||||
if (transfer['canceled_at'])
|
if (transfer['canceled_at'])
|
||||||
this.cancelOpe(transfer, $transfer_html);
|
this.cancel_entry(transfer, $transfer_html);
|
||||||
|
|
||||||
return $transfer_html;
|
return $transfer_html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.cancelOpe = function (ope, $ope = null) {
|
this.cancel_entry = function (entry, $entry = null) {
|
||||||
if (!$ope)
|
if (!$entry)
|
||||||
$ope = this.findOpe(ope["id"], ope["type"]);
|
$entry = this.find_entry(entry["id"], entry["type"]);
|
||||||
|
|
||||||
var cancel = 'Annulé';
|
var cancel = 'Annulé';
|
||||||
var canceled_at = dateUTCToParis(ope['canceled_at']);
|
var canceled_at = dateUTCToParis(entry['canceled_at']);
|
||||||
if (ope['canceled_by__trigramme'])
|
if (entry['canceled_by__trigramme'])
|
||||||
cancel += ' par ' + ope['canceled_by__trigramme'];
|
cancel += ' par ' + entry['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);
|
$entry.addClass('canceled').find('.canceled').text(cancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._opeGroupHtml = function (opegroup) {
|
this._group_html = function (group) {
|
||||||
var type = opegroup['type'];
|
var type = group['type'];
|
||||||
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'operation':
|
case 'operation':
|
||||||
var $opegroup_html = $(this.template_opegroup);
|
var $group_html = $(this.template_opegroup);
|
||||||
var trigramme = opegroup['on_acc__trigramme'];
|
var trigramme = group['on_acc__trigramme'];
|
||||||
var amount = amountDisplay(
|
var amount = amountDisplay(
|
||||||
parseFloat(opegroup['amount']), opegroup['is_cof'], trigramme);
|
parseFloat(group['amount']), group['is_cof'], trigramme);
|
||||||
break;
|
break;
|
||||||
case 'transfer':
|
case 'transfer':
|
||||||
var $opegroup_html = $(this.template_transfergroup);
|
var $group_html = $(this.template_transfergroup);
|
||||||
$opegroup_html.find('.infos').text('Transferts').end()
|
$group_html.find('.infos').text('Transferts').end()
|
||||||
var trigramme = '';
|
var trigramme = '';
|
||||||
var amount = '';
|
var amount = '';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var at = dateUTCToParis(opegroup['at']).format('HH:mm:ss');
|
var at = dateUTCToParis(group['at']).format('HH:mm:ss');
|
||||||
var comment = opegroup['comment'] || '';
|
var comment = group['comment'] || '';
|
||||||
|
|
||||||
$opegroup_html
|
$group_html
|
||||||
.data('type', type)
|
.data('type', type)
|
||||||
.data('id', opegroup['id'])
|
.data('id', group['id'])
|
||||||
.find('.time').text(at).end()
|
.find('.time').text(at).end()
|
||||||
.find('.amount').text(amount).end()
|
.find('.amount').text(amount).end()
|
||||||
.find('.comment').text(comment).end()
|
.find('.comment').text(comment).end()
|
||||||
.find('.trigramme').text(trigramme).end();
|
.find('.trigramme').text(trigramme).end();
|
||||||
|
|
||||||
if (!this.display_trigramme)
|
if (!this.display_trigramme)
|
||||||
$opegroup_html.find('.trigramme').remove();
|
$group_html.find('.trigramme').remove();
|
||||||
$opegroup_html.find('.info').remove();
|
$group_html.find('.info').remove();
|
||||||
|
|
||||||
if (opegroup['valid_by__trigramme'])
|
if (group['valid_by__trigramme'])
|
||||||
$opegroup_html.find('.valid_by').text('Par ' + opegroup['valid_by__trigramme']);
|
$group_html.find('.valid_by').text('Par ' + group['valid_by__trigramme']);
|
||||||
|
|
||||||
return $opegroup_html;
|
return $group_html;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._getOrCreateDay = function (date) {
|
this._get_or_create_day = 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 () {
|
||||||
|
@ -185,24 +185,24 @@ function KHistory(options = {}) {
|
||||||
return $day.data('date', at_ser).text(at.format('D MMMM YYYY'));
|
return $day.data('date', at_ser).text(at.format('D MMMM YYYY'));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.findOpeGroup = function (id, type = "operation") {
|
this.find_group = function (id, type = "operation") {
|
||||||
return this.$container.find('.opegroup').filter(function () {
|
return this.$container.find('.group').filter(function () {
|
||||||
return ($(this).data('id') == id && $(this).data("type") == type)
|
return ($(this).data('id') == id && $(this).data("type") == type)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.findOpe = function (id, type = 'operation') {
|
this.find_entry = function (id, type = 'operation') {
|
||||||
return this.$container.find('.ope').filter(function () {
|
return this.$container.find('.entry').filter(function () {
|
||||||
return ($(this).data('id') == id && $(this).data('type') == type)
|
return ($(this).data('id') == id && $(this).data('type') == type)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.update_opegroup = function (opegroup, type = "operation") {
|
this.update_opegroup = function (group, type = "operation") {
|
||||||
var $opegroup = this.findOpeGroup(opegroup['id'], type);
|
var $group = this.find_group(group['id'], type);
|
||||||
var trigramme = $opegroup.find('.trigramme').text();
|
var trigramme = $group.find('.trigramme').text();
|
||||||
var amount = amountDisplay(
|
var amount = amountDisplay(
|
||||||
parseFloat(opegroup['amount']), opegroup['is_cof'], trigramme);
|
parseFloat(group['amount']), group['is_cof'], trigramme);
|
||||||
$opegroup.find('.amount').text(amount);
|
$group.find('.amount').text(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fetch = function (fetch_options) {
|
this.fetch = function (fetch_options) {
|
||||||
|
@ -214,8 +214,8 @@ function KHistory(options = {}) {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data: options,
|
data: options,
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
for (let opegroup of data['opegroups']) {
|
for (let group of data['groups']) {
|
||||||
that.addOpeGroup(opegroup);
|
that.add_history_group(group);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -239,9 +239,9 @@ function KHistory(options = {}) {
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
window.lock = 0;
|
window.lock = 0;
|
||||||
that.$container.find('.ui-selected').removeClass('ui-selected');
|
that.$container.find('.ui-selected').removeClass('ui-selected');
|
||||||
for (let ope of data["canceled"]) {
|
for (let entry of data["canceled"]) {
|
||||||
ope["type"] = type;
|
entry["type"] = type;
|
||||||
that.cancelOpe(ope);
|
that.cancel_entry(entry);
|
||||||
}
|
}
|
||||||
if (type == "operation") {
|
if (type == "operation") {
|
||||||
for (let opegroup of data["opegroups_to_update"]) {
|
for (let opegroup of data["opegroups_to_update"]) {
|
||||||
|
@ -269,8 +269,8 @@ function KHistory(options = {}) {
|
||||||
"transfers": [],
|
"transfers": [],
|
||||||
"operations": [],
|
"operations": [],
|
||||||
}
|
}
|
||||||
this.$container.find('.ope.ui-selected').each(function () {
|
this.$container.find('.entry.ui-selected').each(function () {
|
||||||
type = $(this).data("group_type");
|
type = $(this).data("type");
|
||||||
opes_to_cancel[`${type}s`].push($(this).data("id"));
|
opes_to_cancel[`${type}s`].push($(this).data("id"));
|
||||||
});
|
});
|
||||||
if (opes_to_cancel["transfers"].length > 0 && opes_to_cancel["operations"].length > 0) {
|
if (opes_to_cancel["transfers"].length > 0 && opes_to_cancel["operations"].length > 0) {
|
||||||
|
@ -296,9 +296,9 @@ function KHistory(options = {}) {
|
||||||
KHistory.default_options = {
|
KHistory.default_options = {
|
||||||
container: '#history',
|
container: '#history',
|
||||||
template_day: '<div class="day"></div>',
|
template_day: '<div class="day"></div>',
|
||||||
template_opegroup: '<div class="opegroup"><span class="time"></span><span class="trigramme"></span><span class="amount"></span><span class="valid_by"></span><span class="comment"></span></div>',
|
template_opegroup: '<div class="group"><span class="time"></span><span class="trigramme"></span><span class="amount"></span><span class="valid_by"></span><span class="comment"></span></div>',
|
||||||
template_transfergroup: '<div class="opegroup"><span class="time"></span><span class="infos"></span><span class="valid_by"></span><span class="comment"></span></div>',
|
template_transfergroup: '<div class="group"><span class="time"></span><span class="infos"></span><span class="valid_by"></span><span class="comment"></span></div>',
|
||||||
template_ope: '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="infos2"></span><span class="addcost"></span><span class="canceled"></span></div>',
|
template_ope: '<div class="entry"><span class="amount"></span><span class="infos1"></span><span class="infos2"></span><span class="addcost"></span><span class="canceled"></span></div>',
|
||||||
template_transfer: '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="glyphicon glyphicon-arrow-right"></span><span class="infos2"></span><span class="canceled"></span></div>',
|
template_transfer: '<div class="entry"><span class="amount"></span><span class="infos1"></span><span class="glyphicon glyphicon-arrow-right"></span><span class="infos2"></span><span class="canceled"></span></div>',
|
||||||
display_trigramme: true,
|
display_trigramme: true,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1253,9 +1253,9 @@ $(document).ready(function() {
|
||||||
// -----
|
// -----
|
||||||
|
|
||||||
OperationWebSocket.add_handler(function(data) {
|
OperationWebSocket.add_handler(function(data) {
|
||||||
for (var i=0; i<data['opegroups'].length; i++) {
|
for (var i=0; i<data['groups'].length; i++) {
|
||||||
if (data['opegroups'][i]['add']) {
|
if (data['groups'][i]['add']) {
|
||||||
khistory.addOpeGroup(data['opegroups'][i]);
|
khistory.add_history_group(data['groups'][i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (var i=0; i<data['checkouts'].length; i++) {
|
for (var i=0; i<data['checkouts'].length; i++) {
|
||||||
|
|
|
@ -1997,7 +1997,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
||||||
"kfet.kpsul",
|
"kfet.kpsul",
|
||||||
{
|
{
|
||||||
"opegroups": [
|
"groups": [
|
||||||
{
|
{
|
||||||
"add": True,
|
"add": True,
|
||||||
"type": "operation",
|
"type": "operation",
|
||||||
|
@ -2009,7 +2009,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
"is_cof": False,
|
"is_cof": False,
|
||||||
"on_acc__trigramme": "000",
|
"on_acc__trigramme": "000",
|
||||||
"valid_by__trigramme": None,
|
"valid_by__trigramme": None,
|
||||||
"opes": [
|
"entries": [
|
||||||
{
|
{
|
||||||
"id": operation.pk,
|
"id": operation.pk,
|
||||||
"addcost_amount": None,
|
"addcost_amount": None,
|
||||||
|
@ -2270,7 +2270,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
||||||
"kfet.kpsul",
|
"kfet.kpsul",
|
||||||
{
|
{
|
||||||
"opegroups": [
|
"groups": [
|
||||||
{
|
{
|
||||||
"add": True,
|
"add": True,
|
||||||
"type": "operation",
|
"type": "operation",
|
||||||
|
@ -2282,7 +2282,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
"is_cof": False,
|
"is_cof": False,
|
||||||
"on_acc__trigramme": "000",
|
"on_acc__trigramme": "000",
|
||||||
"valid_by__trigramme": "100",
|
"valid_by__trigramme": "100",
|
||||||
"opes": [
|
"entries": [
|
||||||
{
|
{
|
||||||
"id": operation.pk,
|
"id": operation.pk,
|
||||||
"addcost_amount": None,
|
"addcost_amount": None,
|
||||||
|
@ -2445,7 +2445,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
||||||
"kfet.kpsul",
|
"kfet.kpsul",
|
||||||
{
|
{
|
||||||
"opegroups": [
|
"groups": [
|
||||||
{
|
{
|
||||||
"add": True,
|
"add": True,
|
||||||
"type": "operation",
|
"type": "operation",
|
||||||
|
@ -2457,7 +2457,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
"is_cof": False,
|
"is_cof": False,
|
||||||
"on_acc__trigramme": "000",
|
"on_acc__trigramme": "000",
|
||||||
"valid_by__trigramme": None,
|
"valid_by__trigramme": None,
|
||||||
"opes": [
|
"entries": [
|
||||||
{
|
{
|
||||||
"id": operation.pk,
|
"id": operation.pk,
|
||||||
"addcost_amount": None,
|
"addcost_amount": None,
|
||||||
|
@ -2604,7 +2604,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
||||||
"kfet.kpsul",
|
"kfet.kpsul",
|
||||||
{
|
{
|
||||||
"opegroups": [
|
"groups": [
|
||||||
{
|
{
|
||||||
"add": True,
|
"add": True,
|
||||||
"type": "operation",
|
"type": "operation",
|
||||||
|
@ -2616,7 +2616,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
"is_cof": False,
|
"is_cof": False,
|
||||||
"on_acc__trigramme": "000",
|
"on_acc__trigramme": "000",
|
||||||
"valid_by__trigramme": "100",
|
"valid_by__trigramme": "100",
|
||||||
"opes": [
|
"entries": [
|
||||||
{
|
{
|
||||||
"id": operation.pk,
|
"id": operation.pk,
|
||||||
"addcost_amount": None,
|
"addcost_amount": None,
|
||||||
|
@ -2716,9 +2716,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
self.checkout.refresh_from_db()
|
self.checkout.refresh_from_db()
|
||||||
self.assertEqual(self.checkout.balance, Decimal("100.00"))
|
self.assertEqual(self.checkout.balance, Decimal("100.00"))
|
||||||
|
|
||||||
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["opegroups"][
|
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["groups"][0][
|
||||||
0
|
"entries"
|
||||||
]["opes"][0]
|
][0]
|
||||||
self.assertEqual(ws_data_ope["addcost_amount"], Decimal("1.00"))
|
self.assertEqual(ws_data_ope["addcost_amount"], Decimal("1.00"))
|
||||||
self.assertEqual(ws_data_ope["addcost_for__trigramme"], "ADD")
|
self.assertEqual(ws_data_ope["addcost_for__trigramme"], "ADD")
|
||||||
|
|
||||||
|
@ -2756,9 +2756,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
self.checkout.refresh_from_db()
|
self.checkout.refresh_from_db()
|
||||||
self.assertEqual(self.checkout.balance, Decimal("100.00"))
|
self.assertEqual(self.checkout.balance, Decimal("100.00"))
|
||||||
|
|
||||||
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["opegroups"][
|
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["groups"][0][
|
||||||
0
|
"entries"
|
||||||
]["opes"][0]
|
][0]
|
||||||
self.assertEqual(ws_data_ope["addcost_amount"], Decimal("0.80"))
|
self.assertEqual(ws_data_ope["addcost_amount"], Decimal("0.80"))
|
||||||
self.assertEqual(ws_data_ope["addcost_for__trigramme"], "ADD")
|
self.assertEqual(ws_data_ope["addcost_for__trigramme"], "ADD")
|
||||||
|
|
||||||
|
@ -2794,9 +2794,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
self.checkout.refresh_from_db()
|
self.checkout.refresh_from_db()
|
||||||
self.assertEqual(self.checkout.balance, Decimal("106.00"))
|
self.assertEqual(self.checkout.balance, Decimal("106.00"))
|
||||||
|
|
||||||
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["opegroups"][
|
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["groups"][0][
|
||||||
0
|
"entries"
|
||||||
]["opes"][0]
|
][0]
|
||||||
self.assertEqual(ws_data_ope["addcost_amount"], Decimal("1.00"))
|
self.assertEqual(ws_data_ope["addcost_amount"], Decimal("1.00"))
|
||||||
self.assertEqual(ws_data_ope["addcost_for__trigramme"], "ADD")
|
self.assertEqual(ws_data_ope["addcost_for__trigramme"], "ADD")
|
||||||
|
|
||||||
|
@ -2830,9 +2830,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
self.accounts["addcost"].refresh_from_db()
|
self.accounts["addcost"].refresh_from_db()
|
||||||
self.assertEqual(self.accounts["addcost"].balance, Decimal("15.00"))
|
self.assertEqual(self.accounts["addcost"].balance, Decimal("15.00"))
|
||||||
|
|
||||||
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["opegroups"][
|
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["groups"][0][
|
||||||
0
|
"entries"
|
||||||
]["opes"][0]
|
][0]
|
||||||
self.assertEqual(ws_data_ope["addcost_amount"], None)
|
self.assertEqual(ws_data_ope["addcost_amount"], None)
|
||||||
self.assertEqual(ws_data_ope["addcost_for__trigramme"], None)
|
self.assertEqual(ws_data_ope["addcost_for__trigramme"], None)
|
||||||
|
|
||||||
|
@ -2865,9 +2865,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
self.accounts["addcost"].refresh_from_db()
|
self.accounts["addcost"].refresh_from_db()
|
||||||
self.assertEqual(self.accounts["addcost"].balance, Decimal("0.00"))
|
self.assertEqual(self.accounts["addcost"].balance, Decimal("0.00"))
|
||||||
|
|
||||||
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["opegroups"][
|
ws_data_ope = self.kpsul_consumer_mock.group_send.call_args[0][1]["groups"][0][
|
||||||
0
|
"entries"
|
||||||
]["opes"][0]
|
][0]
|
||||||
self.assertEqual(ws_data_ope["addcost_amount"], None)
|
self.assertEqual(ws_data_ope["addcost_amount"], None)
|
||||||
self.assertEqual(ws_data_ope["addcost_for__trigramme"], None)
|
self.assertEqual(ws_data_ope["addcost_for__trigramme"], None)
|
||||||
|
|
||||||
|
@ -3174,7 +3174,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
self.kpsul_consumer_mock.group_send.assert_called_once_with(
|
||||||
"kfet.kpsul",
|
"kfet.kpsul",
|
||||||
{
|
{
|
||||||
"opegroups": [
|
"groups": [
|
||||||
{
|
{
|
||||||
"add": True,
|
"add": True,
|
||||||
"type": "operation",
|
"type": "operation",
|
||||||
|
@ -3186,7 +3186,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
"is_cof": False,
|
"is_cof": False,
|
||||||
"on_acc__trigramme": "000",
|
"on_acc__trigramme": "000",
|
||||||
"valid_by__trigramme": None,
|
"valid_by__trigramme": None,
|
||||||
"opes": [
|
"entries": [
|
||||||
{
|
{
|
||||||
"id": operation_list[0].pk,
|
"id": operation_list[0].pk,
|
||||||
"addcost_amount": None,
|
"addcost_amount": None,
|
||||||
|
|
|
@ -1156,7 +1156,7 @@ def kpsul_perform_operations(request):
|
||||||
|
|
||||||
# Websocket data
|
# Websocket data
|
||||||
websocket_data = {}
|
websocket_data = {}
|
||||||
websocket_data["opegroups"] = [
|
websocket_data["groups"] = [
|
||||||
{
|
{
|
||||||
"add": True,
|
"add": True,
|
||||||
"type": "operation",
|
"type": "operation",
|
||||||
|
@ -1170,7 +1170,7 @@ def kpsul_perform_operations(request):
|
||||||
operationgroup.valid_by and operationgroup.valid_by.trigramme or None
|
operationgroup.valid_by and operationgroup.valid_by.trigramme or None
|
||||||
),
|
),
|
||||||
"on_acc__trigramme": operationgroup.on_acc.trigramme,
|
"on_acc__trigramme": operationgroup.on_acc.trigramme,
|
||||||
"opes": [],
|
"entries": [],
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
for operation in operations:
|
for operation in operations:
|
||||||
|
@ -1188,7 +1188,7 @@ def kpsul_perform_operations(request):
|
||||||
"canceled_by__trigramme": None,
|
"canceled_by__trigramme": None,
|
||||||
"canceled_at": None,
|
"canceled_at": None,
|
||||||
}
|
}
|
||||||
websocket_data["opegroups"][0]["opes"].append(ope_data)
|
websocket_data["groups"][0]["entries"].append(ope_data)
|
||||||
# Need refresh from db cause we used update on queryset
|
# Need refresh from db cause we used update on queryset
|
||||||
operationgroup.checkout.refresh_from_db()
|
operationgroup.checkout.refresh_from_db()
|
||||||
websocket_data["checkouts"] = [
|
websocket_data["checkouts"] = [
|
||||||
|
@ -1471,7 +1471,7 @@ def history_json(request):
|
||||||
opegroups = opegroups.filter(on_acc=request.user.profile.account_kfet)
|
opegroups = opegroups.filter(on_acc=request.user.profile.account_kfet)
|
||||||
|
|
||||||
# Construction de la réponse
|
# Construction de la réponse
|
||||||
opegroups_list = []
|
history_groups = []
|
||||||
for opegroup in opegroups:
|
for opegroup in opegroups:
|
||||||
opegroup_dict = {
|
opegroup_dict = {
|
||||||
"type": "operation",
|
"type": "operation",
|
||||||
|
@ -1481,7 +1481,7 @@ def history_json(request):
|
||||||
"checkout_id": opegroup.checkout_id,
|
"checkout_id": opegroup.checkout_id,
|
||||||
"is_cof": opegroup.is_cof,
|
"is_cof": opegroup.is_cof,
|
||||||
"comment": opegroup.comment,
|
"comment": opegroup.comment,
|
||||||
"opes": [],
|
"entries": [],
|
||||||
"on_acc__trigramme": opegroup.on_acc and opegroup.on_acc.trigramme or None,
|
"on_acc__trigramme": opegroup.on_acc and opegroup.on_acc.trigramme or None,
|
||||||
}
|
}
|
||||||
if request.user.has_perm("kfet.is_team"):
|
if request.user.has_perm("kfet.is_team"):
|
||||||
|
@ -1505,8 +1505,8 @@ def history_json(request):
|
||||||
ope_dict["canceled_by__trigramme"] = (
|
ope_dict["canceled_by__trigramme"] = (
|
||||||
ope.canceled_by and ope.canceled_by.trigramme or None
|
ope.canceled_by and ope.canceled_by.trigramme or None
|
||||||
)
|
)
|
||||||
opegroup_dict["opes"].append(ope_dict)
|
opegroup_dict["entries"].append(ope_dict)
|
||||||
opegroups_list.append(opegroup_dict)
|
history_groups.append(opegroup_dict)
|
||||||
for transfergroup in transfergroups:
|
for transfergroup in transfergroups:
|
||||||
if transfergroup.filtered_transfers:
|
if transfergroup.filtered_transfers:
|
||||||
transfergroup_dict = {
|
transfergroup_dict = {
|
||||||
|
@ -1514,7 +1514,7 @@ def history_json(request):
|
||||||
"id": transfergroup.id,
|
"id": transfergroup.id,
|
||||||
"at": transfergroup.at,
|
"at": transfergroup.at,
|
||||||
"comment": transfergroup.comment,
|
"comment": transfergroup.comment,
|
||||||
"opes": [],
|
"entries": [],
|
||||||
}
|
}
|
||||||
if request.user.has_perm("kfet.is_team"):
|
if request.user.has_perm("kfet.is_team"):
|
||||||
transfergroup_dict["valid_by__trigramme"] = (
|
transfergroup_dict["valid_by__trigramme"] = (
|
||||||
|
@ -1533,12 +1533,12 @@ def history_json(request):
|
||||||
transfer_dict["canceled_by__trigramme"] = (
|
transfer_dict["canceled_by__trigramme"] = (
|
||||||
transfer.canceled_by and transfer.canceled_by.trigramme or None
|
transfer.canceled_by and transfer.canceled_by.trigramme or None
|
||||||
)
|
)
|
||||||
transfergroup_dict["opes"].append(transfer_dict)
|
transfergroup_dict["entries"].append(transfer_dict)
|
||||||
opegroups_list.append(transfergroup_dict)
|
history_groups.append(transfergroup_dict)
|
||||||
|
|
||||||
opegroups_list.sort(key=lambda group: group["at"])
|
history_groups.sort(key=lambda group: group["at"])
|
||||||
|
|
||||||
return JsonResponse({"opegroups": opegroups_list})
|
return JsonResponse({"groups": history_groups})
|
||||||
|
|
||||||
|
|
||||||
@teamkfet_required
|
@teamkfet_required
|
||||||
|
|
Loading…
Reference in a new issue