Commit 80eee51d by Damien Moulard

manually delete orders

parent 0ee8de08
......@@ -50,6 +50,28 @@
padding-top: 15px;
}
.order_pill {
flex-direction: row;
}
.pill_order_name {
flex: 3 0 auto;
}
.remove_order_icon {
flex: 0 1 auto;
color: #B22222;
margin-left: 5px;
cursor: pointer;
z-index: 2;
}
.remove_order_icon:hover {
color: #CD5C5C;
}
.remove_order_name {
font-weight: bold;
}
.order_last_update {
font-weight: bold;
}
......
......@@ -625,11 +625,12 @@ function set_product_npa(p_id, npa) {
// Give time for modal to fade
setTimeout(function() {
$.notify(
$(".actions_buttons_area .rights_buttons").notify(
"Produit passé en NPA !",
{
globalPosition:"top right",
className: "success"
position:"bottom right",
className: "success",
arrowShow: false
}
);
}, 500);
......@@ -832,6 +833,8 @@ function create_cdb_order() {
/**
* Update order data of an existing order in couchdb
*
* @returns Promise resolved after update is complete
*/
function update_cdb_order() {
order_doc.products = products;
......@@ -860,6 +863,28 @@ function update_cdb_order() {
}
/**
* Delete an order in couchdb.
*
* @returns Promise resolved after delete is complete
*/
function delete_cdb_order() {
order_doc._deleted = true;
return new Promise((resolve, reject) => {
dbc.put(order_doc, function callback(err, result) {
if (!err && result !== undefined) {
resolve();
} else {
alert("Erreur lors de la suppression de la commande... Si l'erreur persiste contactez un administrateur svp.");
console.log(err);
reject();
}
});
});
}
/**
* Create the Product Orders in Odoo
*/
function create_orders() {
......@@ -965,8 +990,8 @@ function create_orders() {
get_order_attachments();
// Clear data
order_doc._deleted = true;
update_cdb_order().then(() => {
delete_cdb_order().finally(() => {
// Continue with workflow anyway
update_order_selection_screen().then(() => {
reset_data();
switch_screen('orders_created');
......@@ -1721,6 +1746,44 @@ function update_order_selection_screen() {
}
$(".order_pill").on("click", order_pill_on_click);
$(".remove_order_icon").on("click", function(e) {
e.preventDefault();
e.stopImmediatePropagation();
order_name_container = $(this).prev()[0];
let order_id = $(order_name_container).text();
let modal_remove_order = $('#templates #modal_remove_order');
modal_remove_order.find(".remove_order_name").text(order_id);
openModal(
modal_remove_order.html(),
() => {
if (is_time_to('validate_remove_order')) {
dbc.get(order_id).then((doc) => {
order_doc = doc;
delete_cdb_order().then(() => {
update_order_selection_screen().then(() => {
reset_data();
setTimeout(function() {
$.notify(
"Commande supprimée !",
{
globalPosition:"top left",
className: "success"
}
);
}, 500);
});
})
.catch(() => {
console.log("error deleting order");
});
});
}
},
'Valider'
);
});
}
resolve();
......@@ -1888,6 +1951,41 @@ $(document).ready(function() {
}
});
$("#delete_order_button").on("click", function(e) {
if (is_time_to('press_delete_order_button', 1000)) {
let modal_remove_order = $('#templates #modal_remove_order');
modal_remove_order.find(".remove_order_name").text(order_doc._id);
openModal(
modal_remove_order.html(),
() => {
if (is_time_to('validate_remove_order')) {
delete_cdb_order().then(() => {
update_order_selection_screen().then(() => {
reset_data();
switch_screen('order_selection');
setTimeout(function() {
$.notify(
"Commande supprimée !",
{
globalPosition:"top left",
className: "success"
}
);
}, 500);
});
})
.catch(() => {
console.log("error deleting order");
});
}
},
'Valider'
);
}
});
$('#back_to_order_selection_from_main').on('click', function() {
if (is_time_to('back_to_order_selection_from_main', 1000)) {
back();
......
......@@ -41,6 +41,9 @@
<i class="fas fa-arrow-left"></i>&nbsp; Retour
</button>
<div class="rights_buttons">
<button type="button" class='btn--danger' id="delete_order_button">
Supprimer la commande
</button>
<button type="button" class='btn--primary' id="do_inventory" style="display:none;">
Faire un inventaire
</button>
......@@ -143,6 +146,7 @@
<div id="order_pill_template">
<div class="pill order_pill btn btn--primary">
<span class="pill_order_name"></span>
<i class="fas fa-times remove_order_icon"></i>
</div>
</div>
......@@ -174,6 +178,15 @@
<hr/>
</div>
<div id="modal_remove_order">
<h3>Attention !</h3>
<p>
Vous vous apprêtez à supprimer cette commande en cours : <span class="remove_order_name"></span>.<br/>
</p>
<p>Êtez-vous sûr ?</p>
<hr/>
</div>
<div id="modal_remove_supplier">
<h3>Attention !</h3>
<p>
......
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