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
a5931d7c
Commit
a5931d7c
authored
May 05, 2022
by
Damien Moulard
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ticket_2828' into 'dev_cooperatic'
Ticket 2828 See merge request
!171
parents
e5f44f2b
7dfcbf2f
Pipeline
#2184
passed with stage
in 1 minute 32 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
182 additions
and
35 deletions
+182
-35
shelfs.css
shelfs/static/css/shelfs.css
+7
-1
shelf_inventory.js
shelfs/static/js/shelf_inventory.js
+172
-34
shelf_inventory.html
templates/shelfs/shelf_inventory.html
+3
-0
No files found.
shelfs/static/css/shelfs.css
View file @
a5931d7c
...
...
@@ -147,7 +147,12 @@ div#container_edition {
#edition_input_label
{
margin-right
:
5px
;
}
#product_uom
{
font-size
:
small
;
}
#reset_to_previous_qty
{
cursor
:
pointer
;
}
.blink_me
{
animation
:
blinker
1s
ease-in-out
;
}
...
...
@@ -282,3 +287,4 @@ hr {
visibility
:
visible
;
opacity
:
1
;
}
shelfs/static/js/shelf_inventory.js
View file @
a5931d7c
...
...
@@ -26,7 +26,7 @@ var shelf = null,
search_chars
=
[],
user_comments
=
''
,
adding_product
=
false
,
// True if modal to add a product is open.
barcodes
=
null
,
// Barcodes stored locally
// datetime for which shelf's ongoing_inv_start_datetime is considered null
default_inventory_start_datetime
=
"0001-01-01 00:00:00"
;
...
...
@@ -46,19 +46,98 @@ Number.isSafeInteger = Number.isSafeInteger || function (value) {
return
Number
.
isInteger
(
value
)
&&
Math
.
abs
(
value
)
<=
Number
.
MAX_SAFE_INTEGER
;
};
function
back
()
{
document
.
location
.
href
=
parent_location
;
}
function
get_added_qties_sum
(
item
)
{
let
total
=
null
;
function
add
(
accumulator
,
a
)
{
// for array sum
result
=
0
;
if
(
a
)
{
if
(
item
.
uom_id
[
1
]
==
"kg"
)
{
if
(
typeof
a
===
"string"
)
{
a
=
a
.
replace
(
','
,
'.'
)
}
result
=
parseFloat
(
accumulator
)
+
parseFloat
(
a
);
result
=
result
.
toFixed
(
3
);
}
else
{
result
=
parseInt
(
accumulator
,
10
)
+
parseInt
(
a
,
10
);
}
}
return
result
;
}
if
(
typeof
item
.
added_qties
!=
"undefined"
&&
item
.
added_qties
.
length
>
0
)
{
total
=
item
.
added_qties
.
reduce
(
add
);
}
return
total
;
}
function
barcode_analyzer
(
chars
)
{
let
barcode
=
chars
;
if
(
barcode
&&
barcode
.
length
>=
13
)
{
barcode
=
barcode
.
substring
(
barcode
.
length
-
13
);
}
else
if
(
barcode
&&
barcode
.
length
==
12
&&
barcode
.
indexOf
(
'0'
)
!==
0
)
{
// User may use a scanner which remove leading 0
barcode
=
'0'
+
barcode
;
}
else
{
//manually submitted after correction
var
barcode_input
=
$
(
'#search_input'
);
barcode
=
barcode_input
.
val
();
}
document
.
getElementById
(
'search_input'
).
value
=
''
;
$
(
'table.dataTable'
).
DataTable
()
.
search
(
''
)
.
draw
();
// If modal to add a product is open
if
(
adding_product
)
{
$
(
'input.add_product_input'
).
val
(
barcode
);
do_add_product
();
}
else
{
select_product_from_bc
(
barcode
);
}
}
function
reset_previous_value
()
{
if
(
editing_item
!==
null
)
{
if
(
typeof
editing_item
.
added_qties
!==
"undefined"
)
{
editing_item
.
qty
-=
editing_item
.
added_qties
.
pop
();
}
$
(
'#edition_input'
).
val
(
editing_item
.
qty
);
$
(
"#reset_to_previous_qty"
).
hide
();
}
}
function
refresh
()
{
location
.
reload
();
}
// Directly send a line to edition when barcode is read
function
select_product_from_bc
(
barcode
)
{
if
(
editing_item
==
null
)
{
var
found
=
null
;
var
found
=
null
,
qty
=
null
;
if
(
isValidEAN13
(
barcode
))
{
var
scannedProduct
=
barcodes
.
get_corresponding_odoo_product
(
barcode
);
if
(
scannedProduct
===
null
)
{
alert
(
"Le code-barre "
+
barcode
+
" ne correspond à aucun article connu."
);
return
-
1
;
}
else
{
barcode
=
scannedProduct
.
barcode
;
if
(
scannedProduct
.
rule
.
length
>
0
&&
scannedProduct
.
rule
!=
"product"
)
{
qty
=
scannedProduct
.
qty
;
}
}
}
if
(
editing_item
===
null
)
{
$
.
each
(
list_to_process
,
function
(
i
,
e
)
{
if
(
e
.
barcode
==
barcode
)
{
found
=
e
;
...
...
@@ -70,25 +149,44 @@ function select_product_from_bc(barcode) {
$
.
each
(
shelf
.
list_processed
,
function
(
i
,
e
)
{
if
(
e
.
barcode
==
barcode
)
{
found
=
e
;
if
(
qty
)
{
let
message
=
"Attention, ce produit a déjà été compté.
\
n"
;
message
+=
"La quantité "
+
qty
+
" n'a pas été ajoutée !
\
n"
;
// temporary add read qty and recorded one to added_qties to compute sum
found
.
added_qties
=
[
qty
,
found
.
qty
]
message
+=
"Le total serait "
+
get_added_qties_sum
(
found
);
alert
(
message
);
qty
=
null
;
}
editing_origin
=
'processed'
;
}
});
}
if
(
found
!==
null
)
{
setLineEdition
(
found
);
delete
found
.
added_qties
;
setLineEdition
(
found
,
qty
);
if
(
editing_origin
===
'to_process'
)
{
let
row
=
table_to_process
.
row
(
$
(
'tr#'
+
found
.
id
));
remove_from_toProcess
(
row
);
}
else
{
let
row
=
table_processed
.
row
(
$
(
'tr#'
+
found
.
id
));
remove_from_processed
(
row
);
}
}
else
{
console
.
log
(
'Code barre introuvable'
);
}
}
else
if
(
barcode
==
editing_item
.
barcode
&&
qty
){
// We scan the same product as the current one
let
edition_input
=
$
(
'#edition_input'
);
if
(
typeof
editing_item
.
added_qties
==
"undefined"
)
{
editing_item
.
added_qties
=
[
edition_input
.
val
()];
}
editing_item
.
added_qties
.
push
(
qty
);
// TODO : add an action icon to view added quantities
editing_item
.
qty
=
get_added_qties_sum
(
editing_item
);
edition_input
.
val
(
editing_item
.
qty
);
}
}
...
...
@@ -140,8 +238,12 @@ function edit_event(clicked) {
}
// Set edition area
function
setLineEdition
(
item
)
{
var
edition_input
=
$
(
'#edition_input'
);
/**
* If qty is not null, it comes from barcode reading result
* */
function
setLineEdition
(
item
,
qty
)
{
var
edition_input
=
$
(
'#edition_input'
),
set_focus
=
true
;
editing_item
=
item
;
$
(
'#product_name'
).
text
(
editing_item
.
name
);
...
...
@@ -154,12 +256,23 @@ function setLineEdition(item) {
edition_input
.
attr
(
'type'
,
'number'
).
attr
(
'step'
,
0.001
)
.
attr
(
'max'
,
9999
);
}
if
(
qty
)
{
/*
To prevent futur data mess if someone scans barcode while focus is on edition input
qty is stored in editing_item object
*/
editing_item
.
qty
=
qty
;
edition_input
.
val
(
qty
);
set_focus
=
false
;
}
// If item is reprocessed, set input with value
if
(
editing_origin
==
'processed'
)
{
edition_input
.
val
(
editing_item
.
qty
);
}
edition_input
.
focus
();
if
(
set_focus
===
true
)
edition_input
.
focus
();
// Make edition area blink when edition button clicked
container_edition
.
classList
.
add
(
'blink_me'
);
...
...
@@ -172,6 +285,7 @@ function clearLineEdition() {
$
(
'#product_name'
).
text
(
''
);
$
(
'#edition_input'
).
val
(
''
);
$
(
'#search_input'
).
focus
();
$
(
"#reset_to_previous_qty"
).
hide
();
}
// Validate product edition
...
...
@@ -766,9 +880,37 @@ function init() {
$(document.documentElement).scrollTop(scrollTo);
*/
});
if
(
$
(
this
).
val
().
length
>
0
)
{
let
reset_icon
=
$
(
"#reset_to_previous_qty"
);
reset_icon
.
show
();
reset_icon
.
off
();
reset_icon
.
on
(
"click"
,
reset_previous_value
);
}
else
{
$
(
"#reset_to_previous_qty"
).
hide
();
}
})
.
on
(
'blur'
,
function
()
{
const
current_val
=
$
(
this
).
val
();
$
(
this
).
off
(
'wheel.disableScroll'
);
if
(
editing_item
!==
null
)
{
//Let's verify if quantity have be changed
if
(
current_val
!=
editing_item
.
qty
)
{
if
(
typeof
editing_item
.
added_qties
!==
"undefined"
)
{
// total may have been affected by manual typing
const
total
=
get_added_qties_sum
(
editing_item
);
if
(
current_val
!=
total
)
{
// add difference in added_qties array
editing_item
.
added_qties
.
push
(
current_val
-
total
);
}
}
else
{
// Init added_qties to take change into account
editing_item
.
added_qties
=
[
editing_item
.
qty
,
current_val
-
editing_item
.
qty
];
}
}
editing_item
.
qty
=
current_val
;
}
});
// client-side validation of numeric inputs, optionally replacing separator sign(s).
...
...
@@ -817,35 +959,30 @@ function init() {
}
});
//
Barcode reader: listen for 13 digits read in a very short time
//
Manual and textual input
$
(
'#search_input'
).
keypress
(
function
(
e
)
{
if
(
e
.
which
>=
48
&&
e
.
which
<=
57
)
{
if
(
e
.
which
>=
48
&&
e
.
which
<=
57
)
{
// figures [0-9]
search_chars
.
push
(
String
.
fromCharCode
(
e
.
which
));
}
else
if
(
e
.
which
==
13
||
search_chars
.
length
>=
13
)
{
barcode_analyzer
();
}
if
(
search_chars
.
length
>=
13
)
{
var
barcode
=
search_chars
.
join
(
""
);
if
(
!
isNaN
(
barcode
))
{
search_chars
=
[];
setTimeout
(
function
()
{
document
.
getElementById
(
'search_input'
).
value
=
''
;
$
(
'table.dataTable'
).
DataTable
()
.
search
(
''
)
.
draw
();
// If modal to add a product is open
if
(
adding_product
)
{
$
(
'input.add_product_input'
).
val
(
barcode
);
do_add_product
();
}
else
{
select_product_from_bc
(
barcode
);
}
},
300
);
}
}
});
$
(
document
).
pos
();
$
(
document
).
on
(
'scan.pos.barcode'
,
function
(
event
)
{
//access `event.code` - barcode data
var
barcode
=
event
.
code
;
barcode_analyzer
(
barcode
);
});
}
// Load barcodes at page loading, then barcodes are stored locally
var
get_barcodes
=
async
function
()
{
if
(
barcodes
==
null
)
barcodes
=
await
init_barcodes
();
};
$
(
document
).
ready
(
function
()
{
// Get Route parameter
...
...
@@ -880,5 +1017,6 @@ $(document).ready(function() {
}
else
{
get_shelf_data
();
}
get_barcodes
();
});
templates/shelfs/shelf_inventory.html
View file @
a5931d7c
...
...
@@ -10,6 +10,7 @@
<script
type=
"text/javascript"
src=
"{% static 'js/download.js' %}"
></script>
<script
type=
"text/javascript"
src=
"{% static 'js/datatables/jquery.dataTables.min.js' %}"
></script>
<script
type=
"text/javascript"
src=
"{% static 'js/datatables/dataTables.plugins.js' %}"
></script>
<script
type=
"text/javascript"
src=
"{% static 'js/jquery.pos.js' %}"
></script>
{% endblock %}
{% block content %}
...
...
@@ -59,6 +60,7 @@
<label
for=
"edition_input"
id=
"edition_input_label"
>
Qté :
</label>
<input
type=
"text"
class=
"number input_small"
id=
"edition_input"
autocomplete=
"off"
required
>
<span
id=
"product_uom"
></span>
<i
class=
"fa fa-undo"
id=
"reset_to_previous_qty"
style=
"display:none;"
></i>
</div>
<div
class=
"col-1 center"
>
<a
class=
"btn"
id=
'edition_cancel'
>
...
...
@@ -172,5 +174,6 @@
</script>
<script
src=
"{% static "
js
/
all_common
.
js
"
%}?
v=
"></script>
<script src="
{%
static
"
js
/
common
.
js
"
%}?
v=
"></script>
<script src='{% static "
js
/
barcodes
.
js
"
%}?
v=
'></script>
<script type="text/javascript" src="{% static '
js
/
shelf_inventory
.
js
'
%}"
></script>
{% endblock %}
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