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
e430d083
Commit
e430d083
authored
Feb 04, 2022
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
linting
parent
79d992f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
61 deletions
+93
-61
envelops.js
envelops/static/js/envelops.js
+48
-34
orders_helper.js
orders/static/js/orders_helper.js
+45
-27
No files found.
envelops/static/js/envelops.js
View file @
e430d083
...
...
@@ -14,7 +14,8 @@ function toggle_error_alert() {
}
function
toggle_success_alert
(
message
)
{
$
(
'#envelop_cashing_success'
).
find
(
".success_alert_content"
).
text
(
message
);
$
(
'#envelop_cashing_success'
).
find
(
".success_alert_content"
)
.
text
(
message
);
$
(
'#envelop_cashing_success'
).
toggle
(
250
);
}
...
...
@@ -24,9 +25,9 @@ function toggle_deleted_alert() {
/**
* Get an envelop from the cash or cheque lists dependings on the params
* @param {String} type
* @param {String} index
* @returns
* @param {String} type
* @param {String} index
* @returns
*/
function
get_envelop_from_type_index
(
type
,
index
)
{
if
(
type
===
"cash"
)
{
...
...
@@ -38,9 +39,9 @@ function get_envelop_from_type_index(type, index) {
/**
* Define a name for an envelop depending on its type, with or with its type
* @param {Object} envelop
* @param {Object} envelop
* @param {String} name_type short | long
* @returns
* @returns
*/
function
get_envelop_name
(
envelop
,
name_type
=
'short'
)
{
let
envelop_name
=
""
;
...
...
@@ -59,10 +60,10 @@ function get_envelop_name(envelop, name_type = 'short') {
/**
* Set the envelops contents on the document (could use a little cleanup someday: don't generate html in js, etc...)
* @param {Object} envelop
* @param {String} envelop_name
* @param {Int} envelop_content_id
* @param {Int} envelop_index
* @param {Object} envelop
* @param {String} envelop_name
* @param {Int} envelop_content_id
* @param {Int} envelop_index
*/
function
set_envelop_dom
(
envelop
,
envelop_name
,
envelop_content_id
,
envelop_index
)
{
var
envelops_section
=
$
(
'#'
+
envelop
.
type
+
'_envelops'
);
...
...
@@ -107,25 +108,28 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde
}
let
envelop_panel
=
$
(
`.panel_
${
envelop_content_id
}
`
);
envelop_panel
.
append
(
`<button class="btn--danger delete_envelop_button item-fluid" id="update_envelop_
${
envelop
.
type
}
_
${
envelop_index
}
">Supprimer l'enveloppe</button>`
);
envelop_panel
.
append
(
`<button class="btn--primary update_envelop_button item-fluid" id="update_envelop_
${
envelop
.
type
}
_
${
envelop_index
}
">Modifier</button>`
);
$
(
".update_envelop_button"
).
off
(
"click"
);
$
(
".update_envelop_button"
).
on
(
"click"
,
function
()
{
let
el_id
=
$
(
this
).
attr
(
"id"
).
split
(
"_"
);
let
el_id
=
$
(
this
).
attr
(
"id"
)
.
split
(
"_"
);
envelop_to_update
=
{
type
:
el_id
[
2
],
index
:
el_id
[
3
],
lines_to_delete
:
[]
}
}
;
set_update_envelop_modal
();
});
$
(
".delete_envelop_button"
).
off
(
"click"
);
$
(
".delete_envelop_button"
).
on
(
"click"
,
function
()
{
let
el_id
=
$
(
this
).
attr
(
"id"
).
split
(
"_"
);
let
el_id
=
$
(
this
).
attr
(
"id"
)
.
split
(
"_"
);
let
type
=
el_id
[
2
];
let
index
=
el_id
[
3
];
let
envelop
=
get_envelop_from_type_index
(
type
,
index
);
...
...
@@ -143,7 +147,7 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde
/**
* Given the raw list of envelop documents, generate the cash and cheque lists
* @param {Array} envelops
* @param {Array} envelops
*/
function
set_envelops
(
envelops
)
{
var
cash_index
=
0
;
...
...
@@ -208,15 +212,17 @@ function set_update_envelop_modal() {
let
envelop_name
=
get_envelop_name
(
envelop
,
'long'
);
let
modal_update_envelop
=
$
(
'#templates #modal_update_envelop'
);
modal_update_envelop
.
find
(
".envelop_name"
).
text
(
envelop_name
);
modal_update_envelop
.
find
(
".envelop_lines"
).
empty
();
let
update_line_template
=
$
(
'#templates #update_envelop_line_template'
);
let
cpt
=
1
;
for
(
let
partner_id
in
envelop
.
envelop_content
)
{
let
line
=
envelop
.
envelop_content
[
partner_id
];
update_line_template
.
find
(
".update_envelop_line"
).
attr
(
'id'
,
`update_line_
${
partner_id
}
`
);
update_line_template
.
find
(
".line_number"
).
html
(
`
${
cpt
}
. `
);
update_line_template
.
find
(
".line_partner_name"
).
text
(
line
.
partner_name
);
...
...
@@ -243,21 +249,26 @@ function set_update_envelop_modal() {
for
(
let
partner_id
in
envelop
.
envelop_content
)
{
let
line
=
envelop
.
envelop_content
[
partner_id
];
$
(
`#update_line_
${
partner_id
}
`
).
find
(
'.line_partner_amount'
).
val
(
line
.
amount
);
$
(
`#update_line_
${
partner_id
}
`
).
find
(
'.line_partner_amount'
)
.
val
(
line
.
amount
);
}
modal
.
find
(
'.envelop_comments'
).
val
((
envelop
.
comments
!==
undefined
)
?
envelop
.
comments
:
''
);
$
(
".delete_envelop_line_icon"
).
off
(
"click"
);
$
(
".delete_envelop_line_icon"
).
on
(
"click"
,
function
()
{
let
line_id
=
$
(
this
).
closest
(
".update_envelop_line"
).
attr
(
"id"
).
split
(
"_"
);
let
line_id
=
$
(
this
).
closest
(
".update_envelop_line"
)
.
attr
(
"id"
)
.
split
(
"_"
);
let
partner_id
=
line_id
[
line_id
.
length
-
1
];
envelop_to_update
.
lines_to_delete
.
push
(
partner_id
);
$
(
this
).
hide
();
$
(
this
).
closest
(
".update_envelop_line"
).
find
(
".deleted_line_through"
).
show
();
})
$
(
this
).
closest
(
".update_envelop_line"
)
.
find
(
".deleted_line_through"
)
.
show
();
});
}
/**
...
...
@@ -269,8 +280,11 @@ function update_envelop() {
// Update lines amounts
let
amount_inputs
=
modal
.
find
(
'.line_partner_amount'
);
amount_inputs
.
each
(
function
(
i
,
e
)
{
let
line_id
=
$
(
e
).
closest
(
".update_envelop_line"
).
attr
(
"id"
).
split
(
"_"
);
amount_inputs
.
each
(
function
(
i
,
e
)
{
let
line_id
=
$
(
e
).
closest
(
".update_envelop_line"
)
.
attr
(
"id"
)
.
split
(
"_"
);
let
partner_id
=
line_id
[
line_id
.
length
-
1
];
envelop
.
envelop_content
[
partner_id
].
amount
=
parseInt
(
$
(
e
).
val
());
...
...
@@ -278,12 +292,12 @@ function update_envelop() {
// Delete lines
for
(
let
partner_id
of
envelop_to_update
.
lines_to_delete
)
{
delete
(
envelop
.
envelop_content
[
partner_id
])
delete
(
envelop
.
envelop_content
[
partner_id
])
;
}
// Envelop comments
envelop
.
comments
=
modal
.
find
(
'.envelop_comments'
).
val
();
dbc
.
put
(
envelop
,
function
callback
(
err
,
result
)
{
envelop_to_update
=
null
;
...
...
@@ -300,7 +314,7 @@ function update_envelop() {
/**
* Delete an envelop from couchdb.
* @param {Object} envelop
* @param {Object} envelop
*/
function
delete_envelop
(
envelop
)
{
if
(
is_time_to
(
'delete_envelop'
,
1000
))
{
...
...
@@ -321,8 +335,8 @@ function delete_envelop(envelop) {
/**
* Send the request to save an envelop payments in Odoo. The envelop will be deleted from couchdb.
* @param {String} type
* @param {String} index
* @param {String} type
* @param {String} index
*/
function
archive_envelop
(
type
,
index
)
{
if
(
is_time_to
(
'archive_envelop'
,
5000
))
{
...
...
@@ -383,7 +397,7 @@ function archive_envelop(type, index) {
}
});
}
else
{
alert
(
"Par sécurité, il faut attendre 5s entre l'encaissement de deux enveloppes."
)
alert
(
"Par sécurité, il faut attendre 5s entre l'encaissement de deux enveloppes."
)
;
}
}
...
...
@@ -397,10 +411,10 @@ function get_envelops() {
}).
then
(
function
(
result
)
{
set_envelops
(
result
.
rows
);
})
.
catch
(
function
(
err
)
{
alert
(
'Erreur lors de la récupération des enveloppes.'
);
console
.
log
(
err
);
});
.
catch
(
function
(
err
)
{
alert
(
'Erreur lors de la récupération des enveloppes.'
);
console
.
log
(
err
);
});
}
$
(
document
).
ready
(
function
()
{
...
...
orders/static/js/orders_helper.js
View file @
e430d083
...
...
@@ -29,7 +29,7 @@ var dbc = null,
var
clicked_order_pill
=
null
;
var
timerId
var
timerId
;
/* - UTILS */
/**
...
...
@@ -117,9 +117,9 @@ function _compute_stats_date_from() {
}
function
debounceFunction
(
func
,
delay
=
1000
)
{
clearTimeout
(
timerId
)
clearTimeout
(
timerId
);
timerId
=
setTimeout
(
func
,
delay
)
timerId
=
setTimeout
(
func
,
delay
);
}
/* - PRODUCTS */
...
...
@@ -196,6 +196,7 @@ function add_product() {
function
compute_products_coverage_qties
()
{
const
pc_adjust
=
$
(
'#percent_adjust_input'
).
val
();
let
coeff
=
1
;
if
(
!
isNaN
(
parseFloat
(
pc_adjust
)))
{
coeff
=
(
1
+
parseFloat
(
pc_adjust
)
/
100
);
}
...
...
@@ -295,15 +296,16 @@ function check_products_data() {
// Remove fetched product id from loaded products list
const
loaded_p_index
=
loaded_products_ids
.
indexOf
(
p_id
);
if
(
loaded_p_index
>
-
1
)
{
loaded_products_ids
.
splice
(
loaded_p_index
,
1
);
}
}
$
(
'.notifyjs-wrapper'
).
trigger
(
'notify-hide'
);
/**
* If loaded p_ids are remaining:
* If loaded p_ids are remaining:
* these products were loaded but don't match the conditions to be fetched anymore.
* Remove them.
*/
...
...
@@ -311,8 +313,9 @@ function check_products_data() {
for
(
pid
of
loaded_products_ids
)
{
const
p_index
=
products
.
findIndex
(
p
=>
p
.
id
==
pid
);
const
p_name
=
products
[
p_index
].
name
;
products
.
splice
(
p_index
,
1
);
$
.
notify
(
`Produit "
${
p_name
}
" retiré de la commande.\nIl a probablement été passé en archivé ou en NPA sur un autre poste.`
,
{
...
...
@@ -735,8 +738,10 @@ function commit_actions_on_product(product, inputs) {
id
:
product
.
id
,
name
:
product
.
name
};
inputs
.
each
(
function
(
i
,
e
)
{
const
input
=
$
(
e
)
inputs
.
each
(
function
(
i
,
e
)
{
const
input
=
$
(
e
);
if
(
input
.
attr
(
'name'
)
==
'npa-actions'
)
{
if
(
input
.
prop
(
'checked'
)
==
true
)
{
actions
.
npa
.
push
(
input
.
val
());
...
...
@@ -800,7 +805,7 @@ function commit_actions_on_product(product, inputs) {
try
{
if
(
data
.
responseJSON
.
code
===
"archiving_with_incoming_qty"
)
{
alert
(
"Ce produit a des quantités entrantes, vous ne pouvez pas l'archiver."
)
alert
(
"Ce produit a des quantités entrantes, vous ne pouvez pas l'archiver."
)
;
}
else
if
(
data
.
responseJSON
.
code
===
"error_stock_update"
)
{
alert
(
'Erreur lors de la mise à zéro du stock du produit archivé. Les actions ont bien été réalisées.'
);
}
else
{
...
...
@@ -1695,7 +1700,10 @@ function display_products(params) {
e
.
preventDefault
();
// On arrow up pressed, focus next row input
let
next_input
=
$
(
this
).
closest
(
"tr"
).
prev
().
find
(
".product_qty_input"
);
let
next_input
=
$
(
this
).
closest
(
"tr"
)
.
prev
()
.
find
(
".product_qty_input"
);
next_input
.
focus
();
// Scroll to a position where the target input is not hidden by the sticky suppliers container
...
...
@@ -1703,7 +1711,7 @@ function display_products(params) {
$
(
"#suppliers_container"
).
offset
().
top
-
$
(
window
).
scrollTop
()
+
$
(
"#suppliers_container"
).
outerHeight
();
const
next_input_top_offset
=
next_input
.
offset
().
top
-
$
(
window
).
scrollTop
();
const
next_input_top_offset
=
next_input
.
offset
().
top
-
$
(
window
).
scrollTop
();
if
(
next_input_top_offset
<
suppliers_container_top_offset
)
{
window
.
scrollTo
({
...
...
@@ -1714,30 +1722,40 @@ function display_products(params) {
e
.
preventDefault
();
// On arrow down pressed, focus previous row input
$
(
this
).
closest
(
"tr"
).
next
().
find
(
".product_qty_input"
).
focus
();
$
(
this
).
closest
(
"tr"
)
.
next
()
.
find
(
".product_qty_input"
)
.
focus
();
}
else
if
(
e
.
which
==
13
)
{
e
.
preventDefault
();
// On enter pressed, focus previous row input
$
(
this
).
closest
(
"tr"
).
next
().
find
(
".product_qty_input"
).
focus
();
$
(
this
).
closest
(
"tr"
)
.
next
()
.
find
(
".product_qty_input"
)
.
focus
();
}
})
.
on
(
'click'
,
'tbody td .product_actions'
,
function
(
e
){
// Save / unsave selected row
.
on
(
'click'
,
'tbody td .product_actions'
,
function
(
e
)
{
// Save / unsave selected row
const
p_id
=
products_table
.
row
(
$
(
this
).
closest
(
'tr'
)).
data
().
id
;
const
product
=
products
.
find
(
p
=>
p
.
id
==
p_id
);
let
modal_product_actions
=
$
(
'#templates #modal_product_actions'
);
modal_product_actions
.
find
(
".product_name"
).
text
(
product
.
name
);
const
product_can_be_archived
=
product
.
incoming_qty
===
0
;
if
(
product_can_be_archived
==
true
)
{
modal_product_actions
.
find
(
'input[name="archive-action"]'
).
prop
(
"disabled"
,
false
);
modal_product_actions
.
find
(
'input[name="archive-action"]'
).
closest
(
"label"
).
removeClass
(
"checkbox_action_disabled"
);
modal_product_actions
.
find
(
'input[name="archive-action"]'
).
prop
(
"disabled"
,
false
);
modal_product_actions
.
find
(
'input[name="archive-action"]'
).
closest
(
"label"
)
.
removeClass
(
"checkbox_action_disabled"
);
}
else
{
modal_product_actions
.
find
(
'input[name="archive-action"]'
).
prop
(
"disabled"
,
true
);
modal_product_actions
.
find
(
'input[name="archive-action"]'
).
closest
(
"label"
).
addClass
(
"checkbox_action_disabled"
);
modal_product_actions
.
find
(
'input[name="archive-action"]'
).
prop
(
"disabled"
,
true
);
modal_product_actions
.
find
(
'input[name="archive-action"]'
).
closest
(
"label"
)
.
addClass
(
"checkbox_action_disabled"
);
}
openModal
(
...
...
@@ -1750,7 +1768,7 @@ function display_products(params) {
'Valider'
,
false
);
modal
.
find
(
'input[name="minimal_stock"]'
).
val
(
product
.
minimal_stock
)
modal
.
find
(
'input[name="minimal_stock"]'
).
val
(
product
.
minimal_stock
)
;
});
...
...
@@ -1981,7 +1999,7 @@ function update_main_screen(params) {
}
function
display_average_consumption_explanation
()
{
openModal
(
$
(
'#explanations'
).
html
())
openModal
(
$
(
'#explanations'
).
html
());
}
/**
* Update DOM display on the order selection screen
...
...
@@ -2355,7 +2373,7 @@ $(document).ready(function() {
return
0
;
});
$
(
document
).
on
(
"click"
,
".average_consumption_explanation_icon"
,
display_average_consumption_explanation
)
$
(
document
).
on
(
"click"
,
".average_consumption_explanation_icon"
,
display_average_consumption_explanation
);
$
.
datepicker
.
regional
[
'fr'
]
=
{
monthNames
:
[
...
...
@@ -2493,18 +2511,18 @@ $(document).ready(function() {
}
});
$
(
document
).
on
(
'click'
,
'.accordion'
,
function
(){
$
(
document
).
on
(
'click'
,
'.accordion'
,
function
()
{
/* Toggle between adding and removing the "active" class,
to highlight the button that controls the panel */
this
.
classList
.
toggle
(
"active"
);
/* Toggle between hiding and showing the active panel */
var
panel
=
this
.
nextElementSibling
;
if
(
panel
.
style
.
display
===
"block"
)
{
panel
.
style
.
display
=
"none"
;
panel
.
style
.
display
=
"none"
;
}
else
{
panel
.
style
.
display
=
"block"
;
panel
.
style
.
display
=
"block"
;
}
});
}
else
{
...
...
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