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
261
Issues
261
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
Paul
third-party
Commits
2d9012a9
Commit
2d9012a9
authored
Jun 11, 2021
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WIP] linting
parent
9f56118c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
112 deletions
+135
-112
reception_index.js
reception/static/js/reception_index.js
+93
-86
reception_produits.js
reception/static/js/reception_produits.js
+42
-26
No files found.
reception/static/js/reception_index.js
View file @
2d9012a9
...
...
@@ -42,7 +42,7 @@ function group_goto(group_index) {
// Find order data
for
(
let
order
of
orders
)
{
if
(
order
.
id
==
order_groups
.
groups
[
group_index
][
i
])
{
order_data
=
order
order_data
=
order
;
}
}
...
...
@@ -55,7 +55,7 @@ function group_goto(group_index) {
/**
* Create a couchdb document for an order if it doesn't exist
* @param {Object} order_data
* @param {Object} order_data
* @param {Boolean} goto if true, go to order page
*/
function
create_order_doc
(
order_data
,
go_to_order
=
false
)
{
...
...
@@ -63,32 +63,33 @@ function create_order_doc(order_data, go_to_order = false) {
dbc
.
get
(
order_doc_id
).
then
(()
=>
{
if
(
go_to_order
===
true
)
{
goto
(
order_data
.
id
)
goto
(
order_data
.
id
)
;
}
})
.
catch
(
function
(
err
)
{
.
catch
(
function
(
err
)
{
// Create if doesn't exist
if
(
err
.
status
===
404
)
{
let
order_doc
=
{
...
order_data
};
order_doc
.
_id
=
order_doc_id
;
dbc
.
put
(
order_doc
,
(
err
)
=>
{
if
(
!
err
)
{
if
(
go_to_order
===
true
)
{
goto
(
order_data
.
id
)
if
(
err
.
status
===
404
)
{
let
order_doc
=
{
...
order_data
};
order_doc
.
_id
=
order_doc_id
;
dbc
.
put
(
order_doc
,
(
err
)
=>
{
if
(
!
err
)
{
if
(
go_to_order
===
true
)
{
goto
(
order_data
.
id
);
}
}
else
{
error
=
{
msg
:
'Erreur dans la creation de la commande dans couchdb'
,
ctx
:
'validatePrices'
,
details
:
err
};
report_JS_error
(
error
,
'reception'
);
console
.
log
(
error
);
}
}
else
{
error
=
{
msg
:
'Erreur dans la creation de la commande dans couchdb'
,
ctx
:
'validatePrices'
,
details
:
err
};
report_JS_error
(
error
,
'reception'
);
console
.
log
(
error
);
}
});
}
});
});
}
});
}
/* ACTIONS */
...
...
@@ -96,7 +97,7 @@ function create_order_doc(order_data, go_to_order = false) {
/**
* Validate all prices of an order
*/
function
validatePrices
()
{
function
validatePrices
()
{
// Loading on
openModal
();
...
...
@@ -119,15 +120,15 @@ function create_order_doc(order_data, go_to_order = false) {
dbc
.
get
(
`order_
${
order
[
'id'
]}
`
).
then
((
doc
)
=>
{
return
dbc
.
remove
(
doc
);
})
.
then
(()
=>
{
callback_update
=
true
;
reload
();
})
.
catch
((
err
)
=>
{
.
then
(()
=>
{
callback_update
=
true
;
reload
();
})
.
catch
((
err
)
=>
{
// No doc found
console
.
log
(
err
);
reload
();
});
console
.
log
(
err
);
reload
();
});
},
error
:
function
()
{
closeModal
();
...
...
@@ -168,7 +169,7 @@ function create_order_doc(order_data, go_to_order = false) {
/**
* Action fired when orders are grouped (new group)
* @returns
* @returns
*/
function
group_action
()
{
let
pswd
=
prompt
(
'Merci de demander à un.e salarié.e le mot de passe pour fusionner ces commandes.'
);
...
...
@@ -194,7 +195,7 @@ function group_action() {
if
(
!
err
)
{
goto
(
group_ids
[
0
]);
}
else
{
alert
(
"Une erreur est survenue lors de la création du groupe. Veuillez ré-essayer plus tard svp."
)
alert
(
"Une erreur est survenue lors de la création du groupe. Veuillez ré-essayer plus tard svp."
)
;
console
.
log
(
err
);
}
});
...
...
@@ -210,35 +211,35 @@ function group_action() {
/**
* Display the order groups.
* Remove the grouped orders from the order table to prevent grouping in multiple groups.
* Remove the grouped orders from the order table to prevent grouping in multiple groups.
*/
function
display_grouped_orders
()
{
if
(
table_orders
!==
null
)
{
let
groups_display_content
=
"<ul>"
;
for
(
let
group_index
in
order_groups
.
groups
)
{
let
group_orders
=
[];
// Extract every order in the groups from the orders table
for
(
group_order_id
of
order_groups
.
groups
[
group_index
])
{
// Look for order in datatable"
for
(
let
i
=
0
;
i
<
table_orders
.
rows
().
data
().
length
;
i
++
)
{
if
(
group_order_id
==
table_orders
.
rows
(
i
).
data
()[
0
].
id
)
{
var
order
=
table_orders
.
rows
(
i
).
data
()[
0
];
group_orders
.
push
(
order
);
// remove table row
table_orders
.
rows
(
i
).
remove
()
.
draw
();
}
}
}
// Display group
document
.
getElementById
(
"container_groups"
).
hidden
=
false
;
let
group_row
=
`<li class="group_line"> Commandes de `
;
for
(
let
i
in
group_orders
)
{
if
(
i
==
group_orders
.
length
-
1
)
{
// last element of list
group_row
+=
"<b>"
+
group_orders
[
i
].
partner
+
"</b> du "
+
group_orders
[
i
].
date_order
+
" : "
;
...
...
@@ -246,7 +247,7 @@ function display_grouped_orders() {
group_row
+=
"<b>"
+
group_orders
[
i
].
partner
+
"</b> du "
+
group_orders
[
i
].
date_order
+
", "
;
}
}
if
(
group_orders
[
0
].
reception_status
==
'False'
)
{
group_row
+=
"<button class='btn--primary' onClick='group_goto("
+
group_index
...
...
@@ -256,7 +257,7 @@ function display_grouped_orders() {
+
group_index
+
")'>Mettre à jour les prix</button>"
;
}
group_row
+=
"</li>"
;
groups_display_content
+=
group_row
;
}
...
...
@@ -311,34 +312,34 @@ function display_orders_table() {
render
:
function
(
data
)
{
switch
(
data
)
{
case
'qty_valid'
:
return
"<span class='btn--success'>Mettre à jour les prix</span>"
;
case
'br_valid'
:
return
"<span class='btn'><i class='far fa-check-circle'></i> Réception OK</span>"
;
case
'False'
:
return
"<span class='btn--primary'>Compter les produits</span>"
;
case
'done'
:
return
"<span class='btn'><i class='far fa-check-circle'></i> Terminé</span>"
;
case
'uprice_valid'
:
return
"<span class='btn--primary'>Mise à jour du prix OK</span>"
;
case
"valid_pending"
:
return
"<span class='btn--info'>En attente de validation</span>"
;
case
'legacy'
:
return
"<span class='btn--success'>Legacy</span>"
;
case
'error_pack_op'
:
return
"<span class='btn--danger'>Erreur pack operations</span>"
;
case
'error_transfer'
:
return
"<span class='btn--danger'>Erreur de transfert</span>"
;
case
'error_picking'
:
return
"<span class='btn--danger'>Erreur validation quantité</span>"
;
case
'/error_uprice'
:
return
"<span class='btn--danger'>Erreur mise à jour du prix</span>"
;
default
:
return
"<span class='btn--warning'>Status inconnu : "
+
data
+
"</span>"
;
case
'qty_valid'
:
return
"<span class='btn--success'>Mettre à jour les prix</span>"
;
case
'br_valid'
:
return
"<span class='btn'><i class='far fa-check-circle'></i> Réception OK</span>"
;
case
'False'
:
return
"<span class='btn--primary'>Compter les produits</span>"
;
case
'done'
:
return
"<span class='btn'><i class='far fa-check-circle'></i> Terminé</span>"
;
case
'uprice_valid'
:
return
"<span class='btn--primary'>Mise à jour du prix OK</span>"
;
case
"valid_pending"
:
return
"<span class='btn--info'>En attente de validation</span>"
;
case
'legacy'
:
return
"<span class='btn--success'>Legacy</span>"
;
case
'error_pack_op'
:
return
"<span class='btn--danger'>Erreur pack operations</span>"
;
case
'error_transfer'
:
return
"<span class='btn--danger'>Erreur de transfert</span>"
;
case
'error_picking'
:
return
"<span class='btn--danger'>Erreur validation quantité</span>"
;
case
'/error_uprice'
:
return
"<span class='btn--danger'>Erreur mise à jour du prix</span>"
;
default
:
return
"<span class='btn--warning'>Status inconnu : "
+
data
+
"</span>"
;
}
},
width
:
"20%"
...
...
@@ -436,7 +437,7 @@ $(document).ready(function() {
openModal
();
$
.
ajaxSetup
({
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)
}
});
// Init couchdb
// Init couchdb
dbc
=
new
PouchDB
(
couchdb_dbname
),
sync
=
PouchDB
.
sync
(
couchdb_dbname
,
couchdb_server
,
{
live
:
true
,
...
...
@@ -445,26 +446,32 @@ $(document).ready(function() {
});
// TODO sync on change : get data, update data & dom
sync
.
on
(
'change'
,
function
(
info
)
{
console
.
log
(
info
);
}).
on
(
'error'
,
function
(
err
)
{
console
.
log
(
err
);
});
// TODO on button click to access order: verif fingerprint & timestamp
// Get or create order groups doc
dbc
.
get
(
"grouped_orders"
).
then
((
doc
)
=>
{
order_groups
=
doc
;
})
.
catch
(
function
(
err
)
{
console
.
log
(
err
);
if
(
err
.
status
===
404
)
{
.
catch
(
function
(
err
)
{
console
.
log
(
err
);
if
(
err
.
status
===
404
)
{
// Create if doesn't exist
dbc
.
put
(
order_groups
,
(
err
,
result
)
=>
{
if
(
!
err
)
{
order_groups
.
_rev
=
result
.
rev
;
}
else
{
console
.
log
(
"document pour les groupes déjà créé"
);
console
.
log
(
err
);
}
});
}
});
dbc
.
put
(
order_groups
,
(
err
,
result
)
=>
{
if
(
!
err
)
{
order_groups
.
_rev
=
result
.
rev
;
}
else
{
console
.
log
(
"document pour les groupes déjà créé"
);
console
.
log
(
err
);
}
});
}
});
// Set date format for DataTable so date ordering can work
$
.
fn
.
dataTable
.
moment
(
'D/M/Y'
);
...
...
reception/static/js/reception_produits.js
View file @
2d9012a9
...
...
@@ -116,13 +116,13 @@ function select_product_from_bc(barcode) {
/**
* Update couchdb order
* @param {int} order_id
* @param {int} order_id
*/
function
update_distant_order
(
order_id
)
{
// TODO insert fingerprint & timestamp
console
.
log
(
order_id
);
dbc
.
put
(
orders
[
order_id
],
(
err
,
result
)
=>
{
dbc
.
put
(
orders
[
order_id
],
(
err
,
result
)
=>
{
if
(
!
err
&&
result
!==
undefined
)
{
orders
[
order_id
].
_rev
=
result
.
rev
;
}
else
{
...
...
@@ -348,8 +348,13 @@ function initLists() {
className
:
"dt-head-center dt-body-center"
,
visible
:
(
reception_status
==
"False"
),
render
:
function
(
data
,
type
,
full
)
{
let
disp
=
[
full
.
product_qty
,
(
full
.
old_qty
!==
undefined
)?
full
.
old_qty
:
full
.
product_qty
].
join
(
"/"
);
return
disp
;
let
disp
=
[
full
.
product_qty
,
(
full
.
old_qty
!==
undefined
)?
full
.
old_qty
:
full
.
product_qty
].
join
(
"/"
);
return
disp
;
},
orderable
:
false
},
...
...
@@ -414,7 +419,7 @@ function initLists() {
orders
[
data
.
id_po
][
'valid_products'
]
=
[];
}
orders
[
data
.
id_po
][
'valid_products'
].
push
(
data
[
'id'
]);
update_distant_order
(
data
.
id_po
)
update_distant_order
(
data
.
id_po
)
;
// Reset search
document
.
getElementById
(
'search_input'
).
value
=
''
;
...
...
@@ -1189,9 +1194,9 @@ function send() {
}
// Set order(s) name in popup DOM
if
(
Object
.
keys
(
orders
).
length
===
1
)
{
// Single order
if
(
Object
.
keys
(
orders
).
length
===
1
)
{
// Single order
document
.
getElementById
(
"order_ref"
).
innerHTML
=
orders
[
Object
.
keys
(
orders
)[
0
]].
name
;
}
else
{
// group
}
else
{
// group
document
.
getElementById
(
"success_order_name_container"
).
hidden
=
true
;
document
.
getElementById
(
"success_orders_name_container"
).
hidden
=
false
;
...
...
@@ -1306,7 +1311,7 @@ function send() {
traditional
:
true
,
contentType
:
"application/json; charset=utf-8"
,
data
:
JSON
.
stringify
(
updates
),
success
:
function
(
data
)
{},
success
:
function
()
{},
error
:
function
()
{
closeModal
();
alert
(
'Erreur dans l
\'
envoi du rapport.'
);
...
...
@@ -1360,6 +1365,7 @@ function openErrorReport() {
// this is necessary because default behavior is overwritten by the listener defined in jquery.pos.js;
$
(
"#error_report"
).
keypress
(
function
(
e
)
{
var
key
=
e
.
keyCode
;
if
(
key
===
13
)
{
this
.
value
+=
"
\
n"
;
}
...
...
@@ -1378,7 +1384,7 @@ function saveErrorReport() {
// Save comments in all orders
for
(
order_id
of
Object
.
keys
(
orders
))
{
orders
[
order_id
].
user_comments
=
user_comments
;
update_distant_order
(
order_id
)
update_distant_order
(
order_id
)
;
}
document
.
getElementById
(
"search_input"
).
focus
();
...
...
@@ -1393,8 +1399,8 @@ var get_barcodes = async function() {
/**
* Init the page according to order(s) data (texts, colors, events...)
*
* @param {Array} partners_display_data
*
* @param {Array} partners_display_data
*/
function
init_dom
(
partners_display_data
)
{
// Grouped orders
...
...
@@ -1580,7 +1586,7 @@ $(document).ready(function() {
let
pathArray
=
window
.
location
.
pathname
.
split
(
'/'
);
let
id
=
pathArray
[
pathArray
.
length
-
1
];
// Init couchdb
// Init couchdb
dbc
=
new
PouchDB
(
couchdb_dbname
),
sync
=
PouchDB
.
sync
(
couchdb_dbname
,
couchdb_server
,
{
live
:
true
,
...
...
@@ -1589,6 +1595,12 @@ $(document).ready(function() {
});
// TODO on sync change : redirect (cf order_helper)
sync
.
on
(
'change'
,
function
(
info
)
{
console
.
log
(
info
);
}).
on
(
'error'
,
function
(
err
)
{
console
.
log
(
err
);
});
// TODO insert fingerprint & timestamp on access to order
// Disable alert errors from datatables
...
...
@@ -1653,7 +1665,8 @@ $(document).ready(function() {
/* Get order info from couchdb */
// Get order groups
let
order_groups
=
[]
let
order_groups
=
[];
dbc
.
get
(
"grouped_orders"
).
then
((
doc
)
=>
{
order_groups
=
doc
.
groups
;
...
...
@@ -1678,8 +1691,9 @@ $(document).ready(function() {
}).
then
(
function
(
result
)
{
// for each order in the group
for
(
let
order_id
of
group_ids
)
{
// find order
// find order
let
order
=
result
.
rows
.
find
(
el
=>
el
.
id
==
'order_'
+
order_id
);
order
=
order
.
doc
;
orders
[
order_id
]
=
order
;
...
...
@@ -1708,9 +1722,22 @@ $(document).ready(function() {
init_dom
(
partners_display_data
);
})
.
catch
(
function
(
e
)
{
let
msg
=
(
'message'
in
e
&&
'name'
in
e
)
?
e
.
name
+
' : '
+
e
.
message
:
''
;
err
=
{
msg
,
ctx
:
'page init - get orders from couchdb'
,
details
:
e
};
console
.
error
(
err
);
report_JS_error
(
err
,
'reception'
);
// Should be there, redirect
alert
(
"Erreur au chargement de cette commande. Vous allez être redirigé."
);
back
();
});
})
.
catch
(
function
(
e
)
{
let
msg
=
(
'message'
in
e
&&
'name'
in
e
)
?
e
.
name
+
' : '
+
e
.
message
:
''
;
err
=
{
msg
,
ctx
:
'page init - get orders from couchdb'
,
details
:
e
};
err
=
{
msg
,
ctx
:
'page init - get grouped orders'
,
details
:
e
};
console
.
error
(
err
);
report_JS_error
(
err
,
'reception'
);
...
...
@@ -1718,15 +1745,4 @@ $(document).ready(function() {
alert
(
"Erreur au chargement de cette commande. Vous allez être redirigé."
);
back
();
});
})
.
catch
(
function
(
e
)
{
let
msg
=
(
'message'
in
e
&&
'name'
in
e
)
?
e
.
name
+
' : '
+
e
.
message
:
''
;
err
=
{
msg
,
ctx
:
'page init - get grouped orders'
,
details
:
e
};
console
.
error
(
err
);
report_JS_error
(
err
,
'reception'
);
// Should be there, redirect
alert
(
"Erreur au chargement de cette commande. Vous allez être redirigé."
);
back
();
});
});
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