Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
third-party
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cooperatic-foodcoops
third-party
Commits
589eaebb
Commit
589eaebb
authored
May 05, 2022
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
INV: delete ongoing inventory from shelves list
parent
e5f44f2b
Pipeline
#2183
passed with stage
in 1 minute 31 seconds
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
135 additions
and
7 deletions
+135
-7
models.py
shelfs/models.py
+23
-0
shelfs.css
shelfs/static/css/shelfs.css
+8
-0
shelfs_index.js
shelfs/static/js/shelfs_index.js
+87
-7
urls.py
shelfs/urls.py
+1
-0
views.py
shelfs/views.py
+8
-0
index.html
templates/shelfs/index.html
+8
-0
No files found.
shelfs/models.py
View file @
589eaebb
...
@@ -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
=
{}
...
...
shelfs/static/css/shelfs.css
View file @
589eaebb
...
@@ -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
;
...
...
shelfs/static/js/shelfs_index.js
View file @
589eaebb
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
()
{
...
...
shelfs/urls.py
View file @
589eaebb
...
@@ -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
),
...
...
shelfs/views.py
View file @
589eaebb
...
@@ -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"""
...
...
templates/shelfs/index.html
View file @
589eaebb
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment