Commit 10127a48 by Damien Moulard

delete envelop button

parent 7a0149bc
Pipeline #1335 passed with stage
in 1 minute 25 seconds
...@@ -91,7 +91,7 @@ class CagetteEnvelops(models.Model): ...@@ -91,7 +91,7 @@ class CagetteEnvelops(models.Model):
if not ('error' in res): if not ('error' in res):
try: try:
if int(float(data['amount']) * 100) == int(float(invoice['residual_signed']) * 100): if int(float(data['amount']) * 100) == int(float(invoice['residual_signed']) * 100):
# This payment is what it was left to pay, so change invoice state # This payment is what was left to pay, so change invoice state
self.o_api.update('account.invoice', [invoice['id']], {'state': 'paid'}) self.o_api.update('account.invoice', [invoice['id']], {'state': 'paid'})
except Exception as e: except Exception as e:
res['error'] = repr(e) res['error'] = repr(e)
......
...@@ -16,6 +16,10 @@ function toggle_success_alert() { ...@@ -16,6 +16,10 @@ function toggle_success_alert() {
$('#envelop_cashing_success').toggle(250); $('#envelop_cashing_success').toggle(250);
} }
function toggle_deleted_alert() {
$('#envelop_deletion_success').toggle(250);
}
// Set an envelop content on the document // Set an envelop content on the document
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 = $('#' + envelop.type + '_envelops');
...@@ -39,7 +43,7 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde ...@@ -39,7 +43,7 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde
} }
new_html += '</div>' new_html += '</div>'
+ '<div class="panel"><ol id="' + envelop_content_id + '"></ol></div>' + '<div class="panel panel_' + envelop_content_id + '"><ol id="' + envelop_content_id + '"></ol></div>'
+ '</div>'; + '</div>';
$(new_html).appendTo(envelops_section); $(new_html).appendTo(envelops_section);
...@@ -58,6 +62,9 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde ...@@ -58,6 +62,9 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde
li_node.appendChild(textnode); // Append the text to <li> li_node.appendChild(textnode); // Append the text to <li>
document.getElementById(envelop_content_id).appendChild(li_node); document.getElementById(envelop_content_id).appendChild(li_node);
} }
let envelop_panel = $(`.panel_${envelop_content_id}`);
envelop_panel.append('<button class="btn--danger delete_envelop_button item-fluid" onClick="openModal(\'<h3>Supprimer enveloppe ?</h3>\', function() {delete_envelop(\'' + envelop.type + '\', ' + envelop_index + ');}, \'Supprimer\')">Supprimer l\'enveloppe</button>');
} }
// Set the envelops data according to their type // Set the envelops data according to their type
...@@ -118,67 +125,94 @@ function set_envelops(envelops) { ...@@ -118,67 +125,94 @@ function set_envelops(envelops) {
} }
} }
function archive_envelop(type, index) { function delete_envelop(type, index) {
$('#envelop_cashing_error').hide(); if (is_time_to('delete_envelop', 1000)) {
$('#envelop_cashing_success').hide(); openModal();
// Loading on
openModal(); var envelop = null;
if (type == "cash") {
envelop = cash_envelops[index];
} else {
envelop = ch_envelops[index];
}
envelop._deleted = 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);
}
});
if (type == "cash") {
envelop = cash_envelops[index];
} else {
envelop = ch_envelops[index];
} }
}
// Proceed to envelop cashing function archive_envelop(type, index) {
$.ajax({ if (is_time_to('archive_envelop', 1000)) {
type: "POST", $('#envelop_cashing_error').hide();
url: "/envelops/archive_envelop", $('#envelop_cashing_success').hide();
headers: { "X-CSRFToken": getCookie("csrftoken") }, // Loading on
dataType: "json", openModal();
traditional: true,
contentType: "application/json; charset=utf-8", if (type == "cash") {
data: JSON.stringify(envelop), envelop = cash_envelops[index];
success: function(response) { } else {
closeModal(); envelop = ch_envelops[index];
}
var display_success_alert = true;
// Handle errors when saving payments // Proceed to envelop cashing
var error_payments = response.error_payments; $.ajax({
var error_message = ""; type: "POST",
url: "/envelops/archive_envelop",
for (var i = 0; i < error_payments.length; i++) { headers: { "X-CSRFToken": getCookie("csrftoken") },
if (error_payments[i].done == false) { dataType: "json",
error_message += "<p>Erreur lors de l'enregistrement du paiement de <b>" + error_payments[i]['partner_name'] traditional: true,
+ "</b> (id odoo : " + error_payments[i]['partner_id'] + ", valeur à encaisser : " + error_payments[i]['amount'] + "€)."; contentType: "application/json; charset=utf-8",
error_message += "<br/><b>L'opération est à reprendre manuellement dans Odoo pour ce paiement.</b></p>"; data: JSON.stringify(envelop),
success: function(response) {
closeModal();
var display_success_alert = true;
// Handle errors when saving payments
var error_payments = response.error_payments;
var error_message = "";
for (var i = 0; i < error_payments.length; i++) {
if (error_payments[i].done == false) {
error_message += "<p>Erreur lors de l'enregistrement du paiement de <b>" + error_payments[i]['partner_name']
+ "</b> (id odoo : " + error_payments[i]['partner_id'] + ", valeur à encaisser : " + error_payments[i]['amount'] + "€).";
error_message += "<br/><b>L'opération est à reprendre manuellement dans Odoo pour ce paiement.</b></p>";
}
} }
}
// If error during envelop deletion // If error during envelop deletion
var response_envelop = response.envelop; var response_envelop = response.envelop;
if (response_envelop == "error") { if (response_envelop == "error") {
error_message += "<p>Erreur lors de la suppression de l'enveloppe.<br/>"; error_message += "<p>Erreur lors de la suppression de l'enveloppe.<br/>";
error_message += "<b>Sauf contre-indication explicite, les paiements ont bien été enregistrés.</b><br/>"; error_message += "<b>Sauf contre-indication explicite, les paiements ont bien été enregistrés.</b><br/>";
error_message += "Les paiements déjà comptabilisés ne le seront pas à nouveau, vous pouvez ré-essayer. Si l'erreur persiste, l'enveloppe devra être supprimée manuellement.</p>"; error_message += "Les paiements déjà comptabilisés ne le seront pas à nouveau, vous pouvez ré-essayer. Si l'erreur persiste, l'enveloppe devra être supprimée manuellement.</p>";
display_success_alert = false; display_success_alert = false;
} }
if (error_message !== "") { if (error_message !== "") {
$('#error_alert_txt').html(error_message); $('#error_alert_txt').html(error_message);
toggle_error_alert(); toggle_error_alert();
} }
if (display_success_alert) { if (display_success_alert) {
toggle_success_alert(); toggle_success_alert();
}
},
error: function() {
closeModal();
alert('Erreur serveur. Merci de ne pas ré-encaisser l\'enveloppe qui a causé l\'erreur.');
} }
}, });
error: function() { }
closeModal();
alert('Erreur serveur. Merci de ne pas ré-encaisser l\'enveloppe qui a causé l\'erreur.');
}
});
} }
// Get all the envelops from couch db // Get all the envelops from couch db
......
...@@ -20,6 +20,10 @@ ...@@ -20,6 +20,10 @@
<div style="width: 90%" class="fl txtleft">Enveloppe encaissée !</div> <div style="width: 90%" class="fl txtleft">Enveloppe encaissée !</div>
<div style="width: 10%" class="fr txtright"><i class="fas fa-times"></i></div> <div style="width: 10%" class="fr txtright"><i class="fas fa-times"></i></div>
</div> </div>
<div id="envelop_deletion_success" class="alert--success clearfix custom_alert" onClick="toggle_deleted_alert()">
<div style="width: 90%" class="fl txtleft">Enveloppe supprimée !</div>
<div style="width: 10%" class="fr txtright"><i class="fas fa-times"></i></div>
</div>
<section class="grid-2 has-gutter"> <section class="grid-2 has-gutter">
<section id="cash"> <section id="cash">
......
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