Commit 5b449b09 by Etienne Freiss

Make old envelop visible

parent d378cd28
Pipeline #1770 failed with stage
in 1 minute 39 seconds
...@@ -111,6 +111,10 @@ class CagetteEnvelops(models.Model): ...@@ -111,6 +111,10 @@ class CagetteEnvelops(models.Model):
def delete_envelop(self, envelop): def delete_envelop(self, envelop):
return self.c_db.delete(envelop) return self.c_db.delete(envelop)
def archive_envelop(self, envelop):
envelop['archive'] = True
return self.c_db.dbc.update([envelop])
def generate_envelop_display_id(self): def generate_envelop_display_id(self):
"""Generate a unique incremental id to display""" """Generate a unique incremental id to display"""
c_db = CouchDB(arg_db='envelops') c_db = CouchDB(arg_db='envelops')
...@@ -172,7 +176,7 @@ class CagetteEnvelops(models.Model): ...@@ -172,7 +176,7 @@ class CagetteEnvelops(models.Model):
else: else:
# Get the oldest check envelops, limited by the number of checks # Get the oldest check envelops, limited by the number of checks
docs = [] docs = []
for item in c_db.dbc.view('index/by_type', key='ch', include_docs=True, limit=payment_data['checks_nb']): for item in c_db.dbc.view('index/by_type_not_archive', key='ch', include_docs=True, limit=payment_data['checks_nb']):
docs.append(item.doc) docs.append(item.doc)
# If only 1 check to save # If only 1 check to save
......
var cash_envelops = []; var cash_envelops = [];
var archive_cash_envelops = [];
var ch_envelops = []; var ch_envelops = [];
var archive_ch_envelops = [];
var envelop_to_update = null; var envelop_to_update = null;
function reset() { function reset() {
$('#cash_envelops').empty(); $('#cash_envelops').empty();
$('#ch_envelops').empty(); $('#ch_envelops').empty();
$('#archive_cash_envelops').empty();
$('#archive_ch_envelops').empty();
archive_cash_envelops = [];
archive_ch_envelops = [];
cash_envelops = []; cash_envelops = [];
ch_envelops = []; ch_envelops = [];
} }
...@@ -14,7 +20,8 @@ function toggle_error_alert() { ...@@ -14,7 +20,8 @@ function toggle_error_alert() {
} }
function toggle_success_alert(message) { function toggle_success_alert(message) {
$('#envelop_cashing_success').find(".success_alert_content").text(message); $('#envelop_cashing_success').find(".success_alert_content")
.text(message);
$('#envelop_cashing_success').toggle(250); $('#envelop_cashing_success').toggle(250);
} }
...@@ -24,9 +31,9 @@ function toggle_deleted_alert() { ...@@ -24,9 +31,9 @@ function toggle_deleted_alert() {
/** /**
* Get an envelop from the cash or cheque lists dependings on the params * Get an envelop from the cash or cheque lists dependings on the params
* @param {String} type * @param {String} type
* @param {String} index * @param {String} index
* @returns * @returns
*/ */
function get_envelop_from_type_index(type, index) { function get_envelop_from_type_index(type, index) {
if (type === "cash") { if (type === "cash") {
...@@ -38,9 +45,9 @@ function get_envelop_from_type_index(type, index) { ...@@ -38,9 +45,9 @@ function get_envelop_from_type_index(type, index) {
/** /**
* Define a name for an envelop depending on its type, with or with its type * Define a name for an envelop depending on its type, with or with its type
* @param {Object} envelop * @param {Object} envelop
* @param {String} name_type short | long * @param {String} name_type short | long
* @returns * @returns
*/ */
function get_envelop_name(envelop, name_type = 'short') { function get_envelop_name(envelop, name_type = 'short') {
let envelop_name = ""; let envelop_name = "";
...@@ -59,13 +66,19 @@ function get_envelop_name(envelop, name_type = 'short') { ...@@ -59,13 +66,19 @@ function get_envelop_name(envelop, name_type = 'short') {
/** /**
* Set the envelops contents on the document (could use a little cleanup someday: don't generate html in js, etc...) * Set the envelops contents on the document (could use a little cleanup someday: don't generate html in js, etc...)
* @param {Object} envelop * @param {Object} envelop
* @param {String} envelop_name * @param {String} envelop_name
* @param {Int} envelop_content_id * @param {Int} envelop_content_id
* @param {Int} envelop_index * @param {Int} envelop_index
*/ */
function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_index) { function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_index) {
var envelops_section = $('#' + envelop.type + '_envelops'); var envelops_section ="";
if (!envelop.archive)
envelops_section = $('#' + envelop.type + '_envelops');
else
envelops_section = $('#archive_' + envelop.type + '_envelops');
// Calculate envelop total amount // Calculate envelop total amount
var total_amount = 0; var total_amount = 0;
...@@ -78,9 +91,11 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde ...@@ -78,9 +91,11 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde
+ '<div class="flex-container">'; + '<div class="flex-container">';
// Allow checking for all cash and first check envelops // Allow checking for all cash and first check envelops
if (envelop.type == 'cash' || envelop.type == 'ch' && envelop_index == 0) { if ((envelop.type == 'cash' || envelop.type == 'ch' && envelop_index == 0) && !envelop.archive) {
new_html += '<button class="accordion w80">' + envelop_name + ' - <i>' + total_amount + '€</i></button>' new_html += '<button class="accordion w80">' + envelop_name + ' - <i>' + total_amount + '€</i></button>'
+ '<button class="btn--success archive_button item-fluid" onClick="openModal(\'<h3>Êtes-vous sûr ?</h3>\', function() {archive_envelop(\'' + envelop.type + '\', ' + envelop_index + ');}, \'Encaisser\', false)">Encaisser</button>'; + '<button class="btn--success archive_button item-fluid" onClick="openModal(\'<h3>Êtes-vous sûr ?</h3>\', function() {archive_envelop(\'' + envelop.type + '\', ' + envelop_index + ');}, \'Encaisser\', false)">Encaisser</button>';
} else if (envelop.archive && envelop.canceled) {
new_html += '<button class="accordion w100">' + envelop_name + ' - <i>' + total_amount + '€</i> (Enveloppe supprimée) </button>';
} else { } else {
new_html += '<button class="accordion w100">' + envelop_name + ' - <i>' + total_amount + '€</i></button>'; new_html += '<button class="accordion w100">' + envelop_name + ' - <i>' + total_amount + '€</i></button>';
} }
...@@ -107,53 +122,66 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde ...@@ -107,53 +122,66 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde
} }
let envelop_panel = $(`.panel_${envelop_content_id}`); let envelop_panel = $(`.panel_${envelop_content_id}`);
envelop_panel.append(`<button class="btn--danger delete_envelop_button item-fluid" id="update_envelop_${envelop.type}_${envelop_index}">Supprimer l'enveloppe</button>`);
envelop_panel.append(`<button class="btn--primary update_envelop_button item-fluid" id="update_envelop_${envelop.type}_${envelop_index}">Modifier</button>`);
$(".update_envelop_button").off("click"); if (envelop.comments) envelop_panel.append(`<p> Commentaire : ${envelop.comments}</p>`);
$(".update_envelop_button").on("click", function() {
let el_id = $(this).attr("id").split("_");
envelop_to_update = { if (!envelop.archive) {
type: el_id[2], let envelop_panel = $(`.panel_${envelop_content_id}`);
index: el_id[3],
lines_to_delete: []
}
set_update_envelop_modal();
});
$(".delete_envelop_button").off("click"); envelop_panel.append(`<button class="btn--danger delete_envelop_button item-fluid" id="update_envelop_${envelop.type}_${envelop_index}">Supprimer l'enveloppe</button>`);
$(".delete_envelop_button").on("click", function() { envelop_panel.append(`<button class="btn--primary update_envelop_button item-fluid" id="update_envelop_${envelop.type}_${envelop_index}">Modifier</button>`);
let el_id = $(this).attr("id").split("_");
let type = el_id[2];
let index = el_id[3];
let envelop = get_envelop_from_type_index(type, index);
openModal( $(".update_envelop_button").off("click");
"<h3>Supprimer l'enveloppe ?</h3>", $(".update_envelop_button").on("click", function() {
function() { let el_id = $(this).attr("id")
delete_envelop(envelop); .split("_");
},
'Supprimer'
);
});
envelop_to_update = {
type: el_id[2],
index: el_id[3],
lines_to_delete: []
};
set_update_envelop_modal();
});
$(".delete_envelop_button").off("click");
$(".delete_envelop_button").on("click", function() {
let el_id = $(this).attr("id")
.split("_");
let type = el_id[2];
let index = el_id[3];
let envelop = get_envelop_from_type_index(type, index);
openModal(
"<h3>Supprimer l'enveloppe ?</h3>",
function() {
archive_canceled_envelop(envelop);
},
'Supprimer'
);
});
}
} }
/** /**
* Given the raw list of envelop documents, generate the cash and cheque lists * Given the raw list of envelop documents, generate the cash and cheque lists
* @param {Array} envelops * @param {Array} envelops
*/ */
function set_envelops(envelops) { function set_envelops(envelops) {
var cash_index = 0; var cash_index = 0;
var ch_index = 0; var ch_index = 0;
var archive_cash_index = 0;
var archive_ch_index = 0;
reset(); reset();
for (var i= 0; i < envelops.length; i++) { for (var i= 0; i < envelops.length; i++) {
var envelop = envelops[i].doc; var envelop = envelops[i].doc;
if (envelop.type == "cash") { //If the envelop is archived and more than 1 year old we delete it
if (envelop.archive && (new Date()-new Date(envelop.creation_date))/ (1000 * 3600 * 24 * 365)>1) {
delete_envelop(envelop);
} else if (envelop.type == "cash" && envelop.archive != true) {
cash_envelops.push(envelop); cash_envelops.push(envelop);
let envelop_name = get_envelop_name(envelop); let envelop_name = get_envelop_name(envelop);
...@@ -162,7 +190,16 @@ function set_envelops(envelops) { ...@@ -162,7 +190,16 @@ function set_envelops(envelops) {
set_envelop_dom(envelop, envelop_name, envelop_content_id, cash_index); set_envelop_dom(envelop, envelop_name, envelop_content_id, cash_index);
cash_index += 1; cash_index += 1;
} else if (envelop.type == "ch") { } else if (envelop.type == "cash" && envelop.archive == true) {
archive_cash_envelops.push(envelop);
let envelop_name = get_envelop_name(envelop);
let envelop_content_id = 'content_archive_cash_list_' + archive_cash_index;
set_envelop_dom(envelop, envelop_name, envelop_content_id, archive_cash_index);
archive_cash_index += 1;
} else if (envelop.type == "ch" && envelop.archive != true) {
ch_envelops.push(envelop); ch_envelops.push(envelop);
let envelop_name = get_envelop_name(envelop); let envelop_name = get_envelop_name(envelop);
...@@ -171,6 +208,16 @@ function set_envelops(envelops) { ...@@ -171,6 +208,16 @@ function set_envelops(envelops) {
set_envelop_dom(envelop, envelop_name, envelop_content_id, ch_index); set_envelop_dom(envelop, envelop_name, envelop_content_id, ch_index);
ch_index += 1; ch_index += 1;
} else if (envelop.type == "ch" && envelop.archive == true) {
archive_ch_envelops.push(envelop);
let envelop_name = get_envelop_name(envelop);
let envelop_content_id = 'content_archive_ch_list_' + archive_ch_index;
set_envelop_dom(envelop, envelop_name, envelop_content_id, archive_ch_index);
archive_ch_index += 1;
} }
} }
...@@ -208,15 +255,17 @@ function set_update_envelop_modal() { ...@@ -208,15 +255,17 @@ function set_update_envelop_modal() {
let envelop_name = get_envelop_name(envelop, 'long'); let envelop_name = get_envelop_name(envelop, 'long');
let modal_update_envelop = $('#templates #modal_update_envelop'); let modal_update_envelop = $('#templates #modal_update_envelop');
modal_update_envelop.find(".envelop_name").text(envelop_name); modal_update_envelop.find(".envelop_name").text(envelop_name);
modal_update_envelop.find(".envelop_lines").empty(); modal_update_envelop.find(".envelop_lines").empty();
let update_line_template = $('#templates #update_envelop_line_template'); let update_line_template = $('#templates #update_envelop_line_template');
let cpt = 1; let cpt = 1;
for (let partner_id in envelop.envelop_content) { for (let partner_id in envelop.envelop_content) {
let line = envelop.envelop_content[partner_id]; let line = envelop.envelop_content[partner_id];
update_line_template.find(".update_envelop_line").attr('id', `update_line_${partner_id}`); update_line_template.find(".update_envelop_line").attr('id', `update_line_${partner_id}`);
update_line_template.find(".line_number").html(`${cpt}.&nbsp;`); update_line_template.find(".line_number").html(`${cpt}.&nbsp;`);
update_line_template.find(".line_partner_name").text(line.partner_name); update_line_template.find(".line_partner_name").text(line.partner_name);
...@@ -243,21 +292,26 @@ function set_update_envelop_modal() { ...@@ -243,21 +292,26 @@ function set_update_envelop_modal() {
for (let partner_id in envelop.envelop_content) { for (let partner_id in envelop.envelop_content) {
let line = envelop.envelop_content[partner_id]; let line = envelop.envelop_content[partner_id];
$(`#update_line_${partner_id}`).find('.line_partner_amount').val(line.amount); $(`#update_line_${partner_id}`).find('.line_partner_amount')
.val(line.amount);
} }
modal.find('.envelop_comments').val((envelop.comments !== undefined) ? envelop.comments : ''); modal.find('.envelop_comments').val((envelop.comments !== undefined) ? envelop.comments : '');
$(".delete_envelop_line_icon").off("click"); $(".delete_envelop_line_icon").off("click");
$(".delete_envelop_line_icon").on("click", function() { $(".delete_envelop_line_icon").on("click", function() {
let line_id = $(this).closest(".update_envelop_line").attr("id").split("_"); let line_id = $(this).closest(".update_envelop_line")
.attr("id")
.split("_");
let partner_id = line_id[line_id.length-1]; let partner_id = line_id[line_id.length-1];
envelop_to_update.lines_to_delete.push(partner_id); envelop_to_update.lines_to_delete.push(partner_id);
$(this).hide(); $(this).hide();
$(this).closest(".update_envelop_line").find(".deleted_line_through").show(); $(this).closest(".update_envelop_line")
}) .find(".deleted_line_through")
.show();
});
} }
/** /**
...@@ -269,8 +323,11 @@ function update_envelop() { ...@@ -269,8 +323,11 @@ function update_envelop() {
// Update lines amounts // Update lines amounts
let amount_inputs = modal.find('.line_partner_amount'); let amount_inputs = modal.find('.line_partner_amount');
amount_inputs.each(function (i,e) {
let line_id = $(e).closest(".update_envelop_line").attr("id").split("_"); amount_inputs.each(function (i, e) {
let line_id = $(e).closest(".update_envelop_line")
.attr("id")
.split("_");
let partner_id = line_id[line_id.length-1]; let partner_id = line_id[line_id.length-1];
envelop.envelop_content[partner_id].amount = parseInt($(e).val()); envelop.envelop_content[partner_id].amount = parseInt($(e).val());
...@@ -278,12 +335,12 @@ function update_envelop() { ...@@ -278,12 +335,12 @@ function update_envelop() {
// Delete lines // Delete lines
for (let partner_id of envelop_to_update.lines_to_delete) { for (let partner_id of envelop_to_update.lines_to_delete) {
delete(envelop.envelop_content[partner_id]) delete(envelop.envelop_content[partner_id]);
} }
// Envelop comments // Envelop comments
envelop.comments = modal.find('.envelop_comments').val(); envelop.comments = modal.find('.envelop_comments').val();
dbc.put(envelop, function callback(err, result) { dbc.put(envelop, function callback(err, result) {
envelop_to_update = null; envelop_to_update = null;
...@@ -299,8 +356,30 @@ function update_envelop() { ...@@ -299,8 +356,30 @@ function update_envelop() {
} }
/** /**
* archive and canceled an envelop from couchdb.
* @param {Object} envelop
*/
function archive_canceled_envelop(envelop) {
if (is_time_to('archive_canceled_envelop', 1000)) {
envelop.archive = true;
envelop.canceled = true;
dbc.put(envelop, function callback(err, result) {
if (!err && result !== undefined) {
toggle_deleted_alert();
get_envelops();
} else {
alert("Erreur lors de la suppression de l'enveloppe... Essaye de recharger la page et réessaye.");
console.log(err);
}
});
}
}
/**
* Delete an envelop from couchdb. * Delete an envelop from couchdb.
* @param {Object} envelop * @param {Object} envelop
*/ */
function delete_envelop(envelop) { function delete_envelop(envelop) {
if (is_time_to('delete_envelop', 1000)) { if (is_time_to('delete_envelop', 1000)) {
...@@ -308,7 +387,6 @@ function delete_envelop(envelop) { ...@@ -308,7 +387,6 @@ function delete_envelop(envelop) {
dbc.put(envelop, function callback(err, result) { dbc.put(envelop, function callback(err, result) {
if (!err && result !== undefined) { if (!err && result !== undefined) {
toggle_deleted_alert();
get_envelops(); get_envelops();
} else { } else {
alert("Erreur lors de la suppression de l'enveloppe... Essaye de recharger la page et réessaye."); alert("Erreur lors de la suppression de l'enveloppe... Essaye de recharger la page et réessaye.");
...@@ -321,8 +399,8 @@ function delete_envelop(envelop) { ...@@ -321,8 +399,8 @@ function delete_envelop(envelop) {
/** /**
* Send the request to save an envelop payments in Odoo. The envelop will be deleted from couchdb. * Send the request to save an envelop payments in Odoo. The envelop will be deleted from couchdb.
* @param {String} type * @param {String} type
* @param {String} index * @param {String} index
*/ */
function archive_envelop(type, index) { function archive_envelop(type, index) {
if (is_time_to('archive_envelop', 1000)) { if (is_time_to('archive_envelop', 1000)) {
...@@ -395,10 +473,10 @@ function get_envelops() { ...@@ -395,10 +473,10 @@ function get_envelops() {
}).then(function (result) { }).then(function (result) {
set_envelops(result.rows); set_envelops(result.rows);
}) })
.catch(function (err) { .catch(function (err) {
alert('Erreur lors de la récupération des enveloppes.'); alert('Erreur lors de la récupération des enveloppes.');
console.log(err); console.log(err);
}); });
} }
$(document).ready(function() { $(document).ready(function() {
......
...@@ -27,7 +27,7 @@ def archive_envelop(request): ...@@ -27,7 +27,7 @@ def archive_envelop(request):
res_envelop = "" res_envelop = ""
envelop = json.loads(request.body.decode()) envelop = json.loads(request.body.decode())
# save each partner payment # save each partner payment
for partner_id in envelop['envelop_content']: for partner_id in envelop['envelop_content']:
# If payment_id in payment details: payment already saved. Skip saving. # If payment_id in payment details: payment already saved. Skip saving.
...@@ -75,8 +75,8 @@ def archive_envelop(request): ...@@ -75,8 +75,8 @@ def archive_envelop(request):
coop_logger.error("Cannot attach payment error message to member : %s", str(e)) coop_logger.error("Cannot attach payment error message to member : %s", str(e))
try: try:
# Delete envelop from couchdb # archive envelop from couchdb
res_envelop = m.delete_envelop(envelop) res_envelop = m.archive_envelop(envelop)
except Exception as e: except Exception as e:
res_envelop = "error" res_envelop = "error"
......
...@@ -53,9 +53,17 @@ class Command(BaseCommand): ...@@ -53,9 +53,17 @@ class Command(BaseCommand):
byTypeMapFunction = '''function(doc) { byTypeMapFunction = '''function(doc) {
emit(doc.type); emit(doc.type);
}''' }'''
byTypeNotArchiveMapFunction = '''function(doc) {
if(doc.archive != true){
emit(doc.type);
}
}'''
views = { views = {
"by_type": { "by_type": {
"map": byTypeMapFunction "map": byTypeMapFunction
},
"by_type_not_archive": {
"map": byTypeNotArchiveMapFunction
} }
} }
self.createView(dbConn, "index", views) self.createView(dbConn, "index", views)
......
...@@ -39,6 +39,18 @@ ...@@ -39,6 +39,18 @@
</div> </div>
</section> </section>
<section id="archive_cash">
<h2 class="txtcenter">Enveloppes de liquide archivées</h2>
<div id="archive_cash_envelops" class="flex-container flex-column-reverse">
</div>
</section>
<section id="archive_ch">
<h2 class="txtcenter">Enveloppes de chèques archivées</h2>
<div id="archive_ch_envelops" class="flex-container flex-column-reverse">
</div>
</section>
</section> </section>
<div id="templates" style="display:none;"> <div id="templates" style="display:none;">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment