An error occurred while fetching merge requests data.
Commit 589eaebb by Damien Moulard

INV: delete ongoing inventory from shelves list

parent e5f44f2b
dev_cooperatic #5673_bug_calendrier_echange_service 3832-makeups-and-member-status-update 4081 4444_improve_presence_recording 4709 4778-reception-dont-get-finished-orders 4809-remove-shelf-value-col-to-reduce-server-load 4880-rapports-reception-faux 4950-douchage-appli-reception 5474-et-5462-Voir-les-rattrapages-choisis-dans-admin-bdm-et-corrige-lenteur-affichage-admin-rattrapages 5641-reception-trier-a-la-maj-prix-dans-ordre-de-pointage-quantites 6286_bug_encaissement_souscription_cheque_espece 6813-marking-parent-gone-when-unpairing-binom-does-not-unsuscribe-parent-from-shift-template 6832--certaines-absences-engendrent-une-erreur 7723-7559-change-purchase-order-workflow-django-side 7731-third-party-side-brinks-pos-export-not-working 7747-inventaire-par-article 7800-make-test-solution-work 7848-cannot-validate-qty-with-decimal-on-kg-product adaptation_supercafoutch adaptation_supercoop adaptation_supercoop_supercafoutch adpatation_chouette assistance_import_article coop_dev_necessitant_modules_bdm_odoo_modifies correctif_nb_rattrapages_creation_binome_avec_ajout_automatique_au_point_negatif export_capital_detenu fix_bug_process_picking fusion_custom_graoucoop graoucoop_backup graoucoop_prod graoucoop_tmp hot_fix_shelf_labels_auto_print impression_etiquettes_rayons integration_lien_precommandes_dans_espace_membre lacagette_prod local_branch meal-voucher-and-label-printer-software-bug migration-v12 pour_graoucoop_prod pour_version_prod_cagette refonte_espace_membre_sc retouches_tickets_supercoop sc-setup-stock-app supercafoutch-preprod supercafoutch-prod-20221003 supercafoutch_prod ticket_4146 supercafoutch_20250120_151258 supercafoutch_20250120_150340 supercafoutch_20240909_080630 supercafoutch_20240609_115709 supercafoutch_20240212_082431 supercafoutch_20240107_181851 supercafoutch_prod_until_240107 supercafoutch-prod-20221003 supercafoutch-230911 supercafoutch-230824 supercafoutch-230823 supercafoutch-230823-the-true-one migration-v12-tag lacagette_20240310_074751 lacagette_20240107_122554 lacagette_20240107_120916 graoucoop_20240609_122614 cagette_testtag cagette-230814 cagette-230630
Pipeline #2183 passed with stage
in 1 minute 31 seconds
...@@ -195,6 +195,29 @@ class Shelf(models.Model): ...@@ -195,6 +195,29 @@ class Shelf(models.Model):
return res return res
def delete_ongoing_inv_data(self):
""" Reset shelf state & inventory data """
res = {}
# Reset shelf state
f = {
'inventory_status': '',
'ongoing_inv_start_datetime': default_inventory_start_datetime
}
try:
res["update"] = self.o_api.update('product.shelfs', self.id, f)
try:
# Delete local file
res["tmp_inventory"] = self.remove_tmp_inventory()
except Exception as e:
pass
except Exception as e:
res['error'] = str(e)
return res
def save_tmp_inventory(self, inventory_data): def save_tmp_inventory(self, inventory_data):
"""Save inventory data in a json temp file""" """Save inventory data in a json temp file"""
res = {} res = {}
......
...@@ -26,6 +26,14 @@ ...@@ -26,6 +26,14 @@
cursor: pointer; cursor: pointer;
} }
.delete_ongoing_inv_icon:hover {
color: #c9302c;
}
.shelf_name {
font-weight: bold;
}
/*View*/ /*View*/
.cancel_search { .cancel_search {
background-color: transparent; background-color: transparent;
......
var shelfs_table = null; var shelfs_table = null,
default_inventory_start_datetime = "0001-01-01 00:00:00";
function init_datatable() { function init_datatable() {
return $('#shelfs').DataTable({ return $('#shelfs').DataTable({
...@@ -10,13 +11,14 @@ function init_datatable() { ...@@ -10,13 +11,14 @@ function init_datatable() {
data:"sort_order", data:"sort_order",
title:"Numéro", title:"Numéro",
width: "10%", width: "10%",
className:"dt-body-center" className:"dt-body-center clickable"
}, },
{data:"name", title:"Nom"}, {data:"name", title:"Nom", className:"clickable"},
// {data:"description", title:"Description", orderable: false}, // {data:"description", title:"Description", orderable: false},
{ {
data:"ongoing_inv_start_datetime", data:"ongoing_inv_start_datetime",
title:"Début inventaire en cours", title:"Début inventaire en cours",
className:"dt-body-center clickable",
render: function (data, type) { render: function (data, type) {
// Sort on data, not rendering // Sort on data, not rendering
if (type == "sort" || type == 'type') if (type == "sort" || type == 'type')
...@@ -34,6 +36,7 @@ function init_datatable() { ...@@ -34,6 +36,7 @@ function init_datatable() {
{ {
data:"date_last_product_added", data:"date_last_product_added",
title:"Dernier ajout produit", title:"Dernier ajout produit",
className:"dt-body-center clickable",
render: function (data, type) { render: function (data, type) {
// Sort on data, not rendering // Sort on data, not rendering
if (type == "sort" || type == 'type') if (type == "sort" || type == 'type')
...@@ -52,6 +55,7 @@ function init_datatable() { ...@@ -52,6 +55,7 @@ function init_datatable() {
{ {
data:"date_last_inventory", data:"date_last_inventory",
title:"Dernier inventaire", title:"Dernier inventaire",
className:"dt-body-center clickable",
render: function (data, type) { render: function (data, type) {
// Sort on data, not rendering // Sort on data, not rendering
if (type == "sort" || type == 'type') if (type == "sort" || type == 'type')
...@@ -67,7 +71,7 @@ function init_datatable() { ...@@ -67,7 +71,7 @@ function init_datatable() {
} }
} }
}, },
{data:"p_nb", title:"Nombre de réfs", width: "5%", className:"dt-body-center"}, {data:"p_nb", title:"Nombre de réfs", width: "5%", className:"dt-body-center clickable"},
{ {
data:"shelf_value", data:"shelf_value",
title:"Valeur théorique du rayon", title:"Valeur théorique du rayon",
...@@ -84,7 +88,7 @@ function init_datatable() { ...@@ -84,7 +88,7 @@ function init_datatable() {
} }
}, },
width: "5%", width: "5%",
className:"dt-body-center" className:"dt-body-center clickable"
}, },
/* NOT IN USE */ /* NOT IN USE */
// { // {
...@@ -130,6 +134,15 @@ function init_datatable() { ...@@ -130,6 +134,15 @@ function init_datatable() {
else else
return "<button class='btn--success do_shelf_inventory'>Inventaire en réserve</button>"; return "<button class='btn--success do_shelf_inventory'>Inventaire en réserve</button>";
} }
},
{
data:"id",
title:"Supprimer inventaire en cours",
className:"dt-body-center",
width: "5%",
render: function () {
return `<i class="fas fa-trash delete_ongoing_inv_icon"></i>`;
}
} }
], ],
dom: 'rtip', dom: 'rtip',
...@@ -146,7 +159,6 @@ function init_datatable() { ...@@ -146,7 +159,6 @@ function init_datatable() {
function get_shelfs_extra_data() { function get_shelfs_extra_data() {
try { try {
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } });
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: '/shelfs/get_shelves_extra_data', url: '/shelfs/get_shelves_extra_data',
...@@ -217,6 +229,58 @@ function go_to_shelf_inventory() { ...@@ -217,6 +229,58 @@ function go_to_shelf_inventory() {
document.location.href = "shelf_inventory/" + row_data.id; document.location.href = "shelf_inventory/" + row_data.id;
} }
function pre_delete_ongoing_inventory() {
let clicked = $(this);
let row_data = getRowData(clicked);
let template = $("#modal_delete_ongoing_inv");
template.find(".shelf_name").text(row_data.name);
openModal(
template.html(),
() => {
delete_ongoing_inventory(row_data);
},
"Valider",
false
);
}
function delete_ongoing_inventory(row_data) {
openModal();
$.ajax({
type: 'POST',
url: `/shelfs/${row_data.id}/delete_ongoing_inv_data`,
dataType:"json",
traditional: true,
contentType: "application/json; charset=utf-8",
success: function() {
row_data.inventory_status = '';
row_data.ongoing_inv_start_datetime = default_inventory_start_datetime;
shelfs_table
.row('#'+row_data.id)
.data(row_data)
.draw();
// Delete shelf data from localstorage
if (Modernizr.localstorage) {
localStorage.removeItem('shelf_' + row_data.id);
}
closeModal();
},
error: function(data) {
if (typeof data.responseJSON != 'undefined') {
console.log(data.responseJSON);
}
closeModal();
alert("Une erreur est survenue...");
}
});
}
function go_to_shelf_view() { function go_to_shelf_view() {
openModal(); openModal();
...@@ -237,11 +301,27 @@ function go_to_shelf_view() { ...@@ -237,11 +301,27 @@ function go_to_shelf_view() {
} }
$(document).ready(function() { $(document).ready(function() {
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } });
// Check if local data is outdated
for (let shelf of shelfs) {
let stored_shelf = JSON.parse(localStorage.getItem('shelf_' + shelf.id));
if (
stored_shelf !== null
&& stored_shelf.ongoing_inv_start_datetime !== undefined
&& shelf.ongoing_inv_start_datetime !== stored_shelf.ongoing_inv_start_datetime
) {
localStorage.removeItem('shelf_' + shelf.id);
}
}
shelfs_table = init_datatable(); shelfs_table = init_datatable();
get_shelfs_extra_data(); get_shelfs_extra_data();
$(document).on('click', 'button.do_shelf_inventory', go_to_shelf_inventory); $(document).on('click', 'button.do_shelf_inventory', go_to_shelf_inventory);
$('#shelfs').on('click', 'tbody td', go_to_shelf_view); $(document).on('click', 'tbody td .delete_ongoing_inv_icon', pre_delete_ongoing_inventory);
$('#shelfs').on('click', 'tbody td.clickable', go_to_shelf_view);
// Search input // Search input
$('#search_input').on('keyup', function () { $('#search_input').on('keyup', function () {
......
...@@ -15,6 +15,7 @@ urlpatterns = [ ...@@ -15,6 +15,7 @@ urlpatterns = [
url(r'^(?P<shelf_id>\d+)/products$', views.products), url(r'^(?P<shelf_id>\d+)/products$', views.products),
url(r'^(?P<shelf_id>\d+)/add_product$', views.add_product), url(r'^(?P<shelf_id>\d+)/add_product$', views.add_product),
url(r'^(?P<shelf_id>\d+)/set_begin_inventory_datetime$', views.set_begin_inventory_datetime), url(r'^(?P<shelf_id>\d+)/set_begin_inventory_datetime$', views.set_begin_inventory_datetime),
url(r'^(?P<shelf_id>\d+)/delete_ongoing_inv_data$', views.delete_ongoing_inv_data),
url(r'^do_shelf_inventory$', views.do_shelf_inventory), url(r'^do_shelf_inventory$', views.do_shelf_inventory),
url(r'^(?P<shelf_id>\d+)/last_inventory_report$', views.get_last_inventory_report), url(r'^(?P<shelf_id>\d+)/last_inventory_report$', views.get_last_inventory_report),
url(r'^shelf_inventory_FAQ', views.shelf_inventory_FAQ), url(r'^shelf_inventory_FAQ', views.shelf_inventory_FAQ),
......
...@@ -70,6 +70,14 @@ def set_begin_inventory_datetime(request, shelf_id): ...@@ -70,6 +70,14 @@ def set_begin_inventory_datetime(request, shelf_id):
else: else:
return JsonResponse({'res': res}) return JsonResponse({'res': res})
def delete_ongoing_inv_data(request, shelf_id):
m = Shelf(shelf_id)
res = m.delete_ongoing_inv_data()
if 'error' in res:
return JsonResponse(res, status=500)
else:
return JsonResponse({'res': res})
def all(request): def all(request):
"""Get all shelves data""" """Get all shelves data"""
......
...@@ -39,6 +39,14 @@ ...@@ -39,6 +39,14 @@
</div> </div>
</div> </div>
<div id="templates" style="display:none;">
<div id="modal_delete_ongoing_inv">
<h4>Attention !</h4>
<p class="msg">Vous vous apprêtez à supprimer les données de l'inventaire en cours du rayon <span class="shelf_name"></span>.</p>
<p>Êtes-vous sûr.e ?</p>
</div>
</div>
<script type="text/javascript"> <script type="text/javascript">
shelfs = {{shelfs|safe}} shelfs = {{shelfs|safe}}
</script> </script>
......
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