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
0
Merge Requests
0
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
Alexis AOUN
third-party
Commits
58ef26b0
Commit
58ef26b0
authored
Jun 16, 2021
by
Damien Moulard
Committed by
Alexis Aoun
Jul 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
linting
parent
26ca1150
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
63 deletions
+70
-63
reception_index.js
reception/static/js/reception_index.js
+35
-30
reception_produits.js
reception/static/js/reception_produits.js
+35
-33
No files found.
reception/static/js/reception_index.js
View file @
58ef26b0
...
@@ -19,26 +19,26 @@ var orders = [],
...
@@ -19,26 +19,26 @@ var orders = [],
/**
/**
* Difference between two dates
* Difference between two dates
* @param {Date} date1
* @param {Date} date1
* @param {Date} date2
* @param {Date} date2
* @returns difference object
* @returns difference object
*/
*/
function
dates_diff
(
date1
,
date2
)
{
function
dates_diff
(
date1
,
date2
)
{
var
diff
=
{}
var
diff
=
{}
;
var
tmp
=
date2
-
date1
;
var
tmp
=
date2
-
date1
;
tmp
=
Math
.
floor
(
tmp
/
1000
);
tmp
=
Math
.
floor
(
tmp
/
1000
);
diff
.
sec
=
tmp
%
60
;
diff
.
sec
=
tmp
%
60
;
tmp
=
Math
.
floor
((
tmp
-
diff
.
sec
)
/
60
);
tmp
=
Math
.
floor
((
tmp
-
diff
.
sec
)
/
60
);
diff
.
min
=
tmp
%
60
;
diff
.
min
=
tmp
%
60
;
tmp
=
Math
.
floor
((
tmp
-
diff
.
min
)
/
60
);
tmp
=
Math
.
floor
((
tmp
-
diff
.
min
)
/
60
);
diff
.
hours
=
tmp
%
24
;
diff
.
hours
=
tmp
%
24
;
tmp
=
Math
.
floor
((
tmp
-
diff
.
hours
)
/
24
);
tmp
=
Math
.
floor
((
tmp
-
diff
.
hours
)
/
24
);
diff
.
days
=
tmp
;
diff
.
days
=
tmp
;
return
diff
;
return
diff
;
}
}
...
@@ -53,27 +53,29 @@ function reload() {
...
@@ -53,27 +53,29 @@ function reload() {
/**
/**
* Check for concurent access to same order before going to reception page.
* Check for concurent access to same order before going to reception page.
* @param {Int} id
* @param {Int} id
*/
*/
function
check_before_goto
(
id
)
{
function
check_before_goto
(
id
)
{
const
order_doc_id
=
'order_'
+
id
;
const
order_doc_id
=
'order_'
+
id
;
dbc
.
get
(
order_doc_id
).
then
((
doc
)
=>
{
dbc
.
get
(
order_doc_id
).
then
((
doc
)
=>
{
if
(
doc
.
last_update
.
fingerprint
!==
null
&&
doc
.
last_update
.
fingerprint
!==
fingerprint
)
{
if
(
doc
.
last_update
.
fingerprint
!==
null
&&
doc
.
last_update
.
fingerprint
!==
fingerprint
)
{
time_diff
=
dates_diff
(
new
Date
(
doc
.
last_update
.
timestamp
),
new
Date
())
time_diff
=
dates_diff
(
new
Date
(
doc
.
last_update
.
timestamp
),
new
Date
())
;
diff_str
=
``
diff_str
=
``
;
if
(
time_diff
.
days
!==
0
)
{
if
(
time_diff
.
days
!==
0
)
{
diff_str
+=
`
${
time_diff
.
days
}
jour(s), `
diff_str
+=
`
${
time_diff
.
days
}
jour(s), `
;
}
}
if
(
time_diff
.
hours
!==
0
)
{
if
(
time_diff
.
hours
!==
0
)
{
diff_str
+=
`
${
time_diff
.
hours
}
heure(s), `
diff_str
+=
`
${
time_diff
.
hours
}
heure(s), `
;
}
}
if
(
time_diff
.
min
!==
0
)
{
if
(
time_diff
.
min
!==
0
)
{
diff_str
+=
`
${
time_diff
.
min
}
min, `
diff_str
+=
`
${
time_diff
.
min
}
min, `
;
}
}
diff_str
+=
`
${
time_diff
.
sec
}
s`
diff_str
+=
`
${
time_diff
.
sec
}
s`
;
let
modal_order_access
=
$
(
'#templates #modal_order_access'
);
let
modal_order_access
=
$
(
'#templates #modal_order_access'
);
modal_order_access
.
find
(
".order_last_update"
).
text
(
diff_str
);
modal_order_access
.
find
(
".order_last_update"
).
text
(
diff_str
);
openModal
(
openModal
(
...
@@ -87,9 +89,9 @@ function check_before_goto(id) {
...
@@ -87,9 +89,9 @@ function check_before_goto(id) {
goto
(
id
);
goto
(
id
);
}
}
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
console
.
log
(
err
);
console
.
log
(
err
);
})
});
}
}
function
goto
(
id
)
{
function
goto
(
id
)
{
...
@@ -140,22 +142,23 @@ function create_order_doc(order_data, go_to_order = false) {
...
@@ -140,22 +142,23 @@ function create_order_doc(order_data, go_to_order = false) {
order_doc
.
_id
=
order_doc_id
;
order_doc
.
_id
=
order_doc_id
;
order_doc
.
last_update
=
{
order_doc
.
last_update
=
{
timestamp
:
Date
.
now
(),
timestamp
:
Date
.
now
(),
fingerprint
:
fingerprint
,
fingerprint
:
fingerprint
};
};
dbc
.
put
(
order_doc
).
then
(()
=>
{
dbc
.
put
(
order_doc
).
then
(()
=>
{
if
(
go_to_order
===
true
)
{
if
(
go_to_order
===
true
)
{
goto
(
order_data
.
id
);
goto
(
order_data
.
id
);
}
}
}).
catch
((
err
)
=>
{
})
error
=
{
.
catch
((
err
)
=>
{
msg
:
'Erreur dans la creation de la commande dans couchdb'
,
error
=
{
ctx
:
'create_order_doc'
,
msg
:
'Erreur dans la creation de la commande dans couchdb'
,
details
:
err
ctx
:
'create_order_doc'
,
};
details
:
err
report_JS_error
(
error
,
'reception'
);
};
console
.
log
(
error
);
report_JS_error
(
error
,
'reception'
);
});
console
.
log
(
error
);
});
}
}
});
});
}
}
...
@@ -523,8 +526,9 @@ $(document).ready(function() {
...
@@ -523,8 +526,9 @@ $(document).ready(function() {
// On distant changes
// On distant changes
sync
.
on
(
'change'
,
function
(
info
)
{
sync
.
on
(
'change'
,
function
(
info
)
{
// If important data changed somewhere else, update local data
// If important data changed somewhere else, update local data
let
need_to_reload
=
false
;
let
need_to_reload
=
false
;
if
(
info
.
direction
===
"pull"
)
{
if
(
info
.
direction
===
"pull"
)
{
for
(
let
doc
of
info
.
change
.
docs
)
{
for
(
let
doc
of
info
.
change
.
docs
)
{
if
(
doc
.
_id
===
"grouped_orders"
)
{
if
(
doc
.
_id
===
"grouped_orders"
)
{
...
@@ -547,6 +551,7 @@ $(document).ready(function() {
...
@@ -547,6 +551,7 @@ $(document).ready(function() {
}
else
{
}
else
{
// Find updated order in local orders & update it if reception status changed
// Find updated order in local orders & update it if reception status changed
let
index
=
orders
.
findIndex
(
order
=>
order
.
id
==
doc
.
id
);
let
index
=
orders
.
findIndex
(
order
=>
order
.
id
==
doc
.
id
);
if
(
index
!==
-
1
&&
orders
[
index
].
reception_status
!==
doc
.
reception_status
)
{
if
(
index
!==
-
1
&&
orders
[
index
].
reception_status
!==
doc
.
reception_status
)
{
orders
[
index
]
=
doc
;
orders
[
index
]
=
doc
;
need_to_reload
=
true
;
need_to_reload
=
true
;
...
...
reception/static/js/reception_produits.js
View file @
58ef26b0
...
@@ -118,7 +118,7 @@ function select_product_from_bc(barcode) {
...
@@ -118,7 +118,7 @@ function select_product_from_bc(barcode) {
function
update_distant_order
(
order_id
)
{
function
update_distant_order
(
order_id
)
{
orders
[
order_id
].
last_update
=
{
orders
[
order_id
].
last_update
=
{
timestamp
:
Date
.
now
(),
timestamp
:
Date
.
now
(),
fingerprint
:
fingerprint
,
fingerprint
:
fingerprint
};
};
dbc
.
put
(
orders
[
order_id
],
(
err
,
result
)
=>
{
dbc
.
put
(
orders
[
order_id
],
(
err
,
result
)
=>
{
...
@@ -135,11 +135,11 @@ function update_distant_order(order_id) {
...
@@ -135,11 +135,11 @@ function update_distant_order(order_id) {
* Update distant orders with local data
* Update distant orders with local data
* @param {int} order_id
* @param {int} order_id
*/
*/
function
update_distant_orders
()
{
function
update_distant_orders
()
{
for
(
let
order_id
in
orders
)
{
for
(
let
order_id
in
orders
)
{
orders
[
order_id
].
last_update
=
{
orders
[
order_id
].
last_update
=
{
timestamp
:
Date
.
now
(),
timestamp
:
Date
.
now
(),
fingerprint
:
fingerprint
,
fingerprint
:
fingerprint
};
};
}
}
...
@@ -147,12 +147,13 @@ function update_distant_order(order_id) {
...
@@ -147,12 +147,13 @@ function update_distant_order(order_id) {
// Update rev of current orders after their update
// Update rev of current orders after their update
for
(
let
doc
of
response
)
{
for
(
let
doc
of
response
)
{
let
order_id
=
doc
.
id
.
split
(
'_'
)[
1
];
let
order_id
=
doc
.
id
.
split
(
'_'
)[
1
];
orders
[
order_id
].
_rev
=
doc
.
rev
orders
[
order_id
].
_rev
=
doc
.
rev
;
}
}
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
console
.
log
(
err
);
console
.
log
(
err
);
})
});
}
}
/* INIT */
/* INIT */
...
@@ -844,12 +845,12 @@ function clearLineEdition() {
...
@@ -844,12 +845,12 @@ function clearLineEdition() {
document
.
getElementById
(
'product_uom'
).
innerHTML
=
''
;
document
.
getElementById
(
'product_uom'
).
innerHTML
=
''
;
}
}
/**
/**
* Update a product info : qty or unit price
* Update a product info : qty or unit price
* @param {Object} productToEdit
* @param {Object} productToEdit
* @param {Float} value if set, use it as new value
* @param {Float} value if set, use it as new value
* @param {Boolean} batch if true, don't update couchdb data here
* @param {Boolean} batch if true, don't update couchdb data here
* @returns
* @returns
*/
*/
function
editProductInfo
(
productToEdit
,
value
=
null
,
batch
=
false
)
{
function
editProductInfo
(
productToEdit
,
value
=
null
,
batch
=
false
)
{
try
{
try
{
...
@@ -986,7 +987,7 @@ function setAllQties() {
...
@@ -986,7 +987,7 @@ function setAllQties() {
.
draw
();
.
draw
();
// Batch update orders
// Batch update orders
update_distant_orders
()
update_distant_orders
()
;
}
}
/* ACTIONS */
/* ACTIONS */
...
@@ -1241,7 +1242,7 @@ function send() {
...
@@ -1241,7 +1242,7 @@ function send() {
closeModal
();
closeModal
();
try
{
try
{
// If step 1 (counting)
// If step 1 (counting)
if
(
reception_status
==
"False"
)
{
if
(
reception_status
==
"False"
)
{
/* Open pop-up with procedure explanation */
/* Open pop-up with procedure explanation */
var
barcodes_to_print
=
false
;
var
barcodes_to_print
=
false
;
...
@@ -1309,18 +1310,18 @@ function send() {
...
@@ -1309,18 +1310,18 @@ function send() {
/* Not last step: update distant data */
/* Not last step: update distant data */
for
(
let
order_id
in
orders
)
{
for
(
let
order_id
in
orders
)
{
// Save current step updated data
// Save current step updated data
orders
[
order_id
].
previous_steps_data
=
{}
orders
[
order_id
].
previous_steps_data
=
{}
;
orders
[
order_id
].
previous_steps_data
[
reception_status
]
=
{
orders
[
order_id
].
previous_steps_data
[
reception_status
]
=
{
updated_products
:
orders
[
order_id
].
updated_products
||
[]
updated_products
:
orders
[
order_id
].
updated_products
||
[]
}
}
;
orders
[
order_id
].
reception_status
=
updateType
;
orders
[
order_id
].
reception_status
=
updateType
;
// Unlock order
// Unlock order
orders
[
order_id
].
last_update
=
{
orders
[
order_id
].
last_update
=
{
timestamp
:
null
,
timestamp
:
null
,
fingerprint
:
null
,
fingerprint
:
null
}
}
;
// Delete temp data
// Delete temp data
delete
orders
[
order_id
].
valid_products
;
delete
orders
[
order_id
].
valid_products
;
delete
orders
[
order_id
].
updated_products
;
delete
orders
[
order_id
].
updated_products
;
...
@@ -1328,7 +1329,7 @@ function send() {
...
@@ -1328,7 +1329,7 @@ function send() {
dbc
.
bulkDocs
(
Object
.
values
(
orders
)).
catch
((
err
)
=>
{
dbc
.
bulkDocs
(
Object
.
values
(
orders
)).
catch
((
err
)
=>
{
console
.
log
(
err
);
console
.
log
(
err
);
})
})
;
}
else
{
}
else
{
// Print etiquettes with new prices
// Print etiquettes with new prices
if
(
updatedProducts
.
length
>
0
)
{
if
(
updatedProducts
.
length
>
0
)
{
...
@@ -1356,8 +1357,9 @@ function send() {
...
@@ -1356,8 +1357,9 @@ function send() {
// We're in a group, remove it & update groups doc
// We're in a group, remove it & update groups doc
if
(
Object
.
keys
(
orders
).
length
>
1
)
{
if
(
Object
.
keys
(
orders
).
length
>
1
)
{
let
groups_doc
=
doc
;
let
groups_doc
=
doc
;
let
first_order_id
=
parseInt
(
Object
.
keys
(
orders
)[
0
]);
let
first_order_id
=
parseInt
(
Object
.
keys
(
orders
)[
0
]);
for
(
let
i
in
groups_doc
.
groups
)
{
for
(
let
i
in
groups_doc
.
groups
)
{
if
(
groups_doc
.
groups
[
i
].
includes
(
first_order_id
))
{
if
(
groups_doc
.
groups
[
i
].
includes
(
first_order_id
))
{
groups_doc
.
groups
.
splice
(
i
,
1
);
groups_doc
.
groups
.
splice
(
i
,
1
);
...
@@ -1370,9 +1372,9 @@ function send() {
...
@@ -1370,9 +1372,9 @@ function send() {
return
dbc
.
bulkDocs
(
couchdb_update_data
);
return
dbc
.
bulkDocs
(
couchdb_update_data
);
})
})
.
catch
(
function
(
err
)
{
.
catch
(
function
(
err
)
{
console
.
log
(
err
)
console
.
log
(
err
);
});
});
}
}
// Back if modal closed
// Back if modal closed
...
@@ -1425,7 +1427,7 @@ function confirm_all_left_is_good() {
...
@@ -1425,7 +1427,7 @@ function confirm_all_left_is_good() {
.
draw
();
.
draw
();
// Batch update orders
// Batch update orders
update_distant_orders
()
update_distant_orders
()
;
closeModal
();
closeModal
();
}
}
...
@@ -1484,17 +1486,17 @@ function init_dom(partners_display_data) {
...
@@ -1484,17 +1486,17 @@ function init_dom(partners_display_data) {
for
(
let
order_id
in
orders
)
{
for
(
let
order_id
in
orders
)
{
orders
[
order_id
].
last_update
=
{
orders
[
order_id
].
last_update
=
{
timestamp
:
null
,
timestamp
:
null
,
fingerprint
:
null
,
fingerprint
:
null
};
};
}
}
dbc
.
bulkDocs
(
Object
.
values
(
orders
)).
then
((
response
)
=>
{
dbc
.
bulkDocs
(
Object
.
values
(
orders
)).
then
((
response
)
=>
{
back
();
back
();
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
console
.
log
(
err
);
console
.
log
(
err
);
})
});
})
})
;
// Grouped orders
// Grouped orders
if
(
Object
.
keys
(
orders
).
length
>
1
)
{
if
(
Object
.
keys
(
orders
).
length
>
1
)
{
...
@@ -1671,7 +1673,7 @@ function init_dom(partners_display_data) {
...
@@ -1671,7 +1673,7 @@ function init_dom(partners_display_data) {
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
$
.
ajaxSetup
({
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)
}
});
$
.
ajaxSetup
({
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)
}
});
fingerprint
=
new
Fingerprint
({
canvas
:
true
}).
get
();
fingerprint
=
new
Fingerprint
({
canvas
:
true
}).
get
();
// Load barcodes
// Load barcodes
...
@@ -1689,7 +1691,7 @@ $(document).ready(function() {
...
@@ -1689,7 +1691,7 @@ $(document).ready(function() {
auto_compaction
:
false
auto_compaction
:
false
});
});
sync
.
on
(
'change'
,
function
(
info
)
{
sync
.
on
(
'change'
,
function
(
info
)
{
if
(
info
.
direction
===
"pull"
)
{
if
(
info
.
direction
===
"pull"
)
{
for
(
const
doc
of
info
.
change
.
docs
)
{
for
(
const
doc
of
info
.
change
.
docs
)
{
// Redirect if one of the current order is being modified somewhere else
// Redirect if one of the current order is being modified somewhere else
...
@@ -1703,7 +1705,7 @@ $(document).ready(function() {
...
@@ -1703,7 +1705,7 @@ $(document).ready(function() {
if
(
err
.
status
===
409
)
{
if
(
err
.
status
===
409
)
{
alert
(
"Une erreur de synchronisation s'est produite, la commande a sûrement été modifiée sur un autre navigateur. Vous allez être redirigé.e."
);
alert
(
"Une erreur de synchronisation s'est produite, la commande a sûrement été modifiée sur un autre navigateur. Vous allez être redirigé.e."
);
back
();
back
();
}
}
console
.
log
(
'erreur sync'
);
console
.
log
(
'erreur sync'
);
console
.
log
(
err
);
console
.
log
(
err
);
});
});
...
@@ -1823,7 +1825,7 @@ $(document).ready(function() {
...
@@ -1823,7 +1825,7 @@ $(document).ready(function() {
user_comments
=
orders
[
Object
.
keys
(
orders
)[
0
]].
user_comments
||
""
;
user_comments
=
orders
[
Object
.
keys
(
orders
)[
0
]].
user_comments
||
""
;
// Indicate that these orders are used in this navigator
// Indicate that these orders are used in this navigator
update_distant_orders
()
update_distant_orders
()
;
// Fetch orders data
// Fetch orders data
fetch_data
();
fetch_data
();
...
...
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