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
20c13305
Commit
20c13305
authored
Jun 30, 2021
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AAC: update order products data when accessing an order
parent
d969d7c1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
100 additions
and
27 deletions
+100
-27
oders_helper_style.css
orders/static/css/oders_helper_style.css
+12
-3
orders_helper.js
orders/static/js/orders_helper.js
+75
-10
models.py
products/models.py
+1
-3
urls.py
products/urls.py
+1
-1
views.py
products/views.py
+3
-4
helper.html
templates/orders/helper.html
+8
-6
No files found.
orders/static/css/oders_helper_style.css
View file @
20c13305
...
@@ -66,10 +66,20 @@
...
@@ -66,10 +66,20 @@
position
:
absolute
;
position
:
absolute
;
}
}
#actions_buttons_area
{
#
main_content
.
actions_buttons_area
{
position
:
absolute
;
position
:
absolute
;
width
:
100%
;
top
:
0
;
top
:
0
;
right
:
0
;
display
:
flex
;
justify-content
:
space-between
;
}
#orders_created
.actions_buttons_area
{
position
:
absolute
;
width
:
100%
;
top
:
0
;
display
:
flex
;
justify-content
:
flex-start
;
}
}
/* -- Order data */
/* -- Order data */
...
@@ -193,7 +203,6 @@
...
@@ -193,7 +203,6 @@
/* - Orders created screen */
/* - Orders created screen */
.order_created_header
{
.order_created_header
{
margin-top
:
15px
;
margin-bottom
:
40px
;
margin-bottom
:
40px
;
}
}
...
...
orders/static/js/orders_helper.js
View file @
20c13305
...
@@ -27,6 +27,8 @@ var dbc = null,
...
@@ -27,6 +27,8 @@ var dbc = null,
},
},
fingerprint
=
null
;
fingerprint
=
null
;
var
clicked_order_pill
=
null
;
/* - UTILS */
/* - UTILS */
...
@@ -53,6 +55,7 @@ function reset_data() {
...
@@ -53,6 +55,7 @@ function reset_data() {
package_qty
:
null
,
package_qty
:
null
,
price
:
null
price
:
null
};
};
clicked_order_pill
=
null
;
}
}
/**
/**
...
@@ -109,17 +112,32 @@ function add_product() {
...
@@ -109,17 +112,32 @@ function add_product() {
return
-
1
;
return
-
1
;
}
}
/*
onst product_ids = products.map(p => p.id);
if (product_ids.length > 0) {
clicked_order_pill.find('.pill_order_name').empty().append(`<i class="fas fa-spinner fa-spin"></i>`);
$.ajax({
$.ajax({
type
:
'GET'
,
type: 'POST',
url
:
'/products/get_product_for_order_helper/'
+
product
.
tpl_id
,
url: '/products/get_product_for_order_helper',
data: JSON.stringify(product_ids),
dataType:"json",
*/
$
.
ajax
({
type
:
'POST'
,
url
:
'/products/get_product_for_order_helper'
,
data
:
JSON
.
stringify
([
product
.
tpl_id
]),
dataType
:
"json"
,
dataType
:
"json"
,
traditional
:
true
,
traditional
:
true
,
contentType
:
"application/json; charset=utf-8"
,
contentType
:
"application/json; charset=utf-8"
,
success
:
function
(
data
)
{
success
:
function
(
data
)
{
if
(
typeof
data
.
id
!=
"undefined"
)
{
let
res
=
data
.
products
[
0
];
data
.
suppliersinfo
=
[];
if
(
typeof
res
.
id
!=
"undefined"
)
{
data
.
default_code
=
' '
;
res
.
suppliersinfo
=
[];
products
.
unshift
(
data
);
res
.
default_code
=
' '
;
products
.
unshift
(
res
);
update_main_screen
({
'sort_order_dir'
:
'desc'
});
update_main_screen
({
'sort_order_dir'
:
'desc'
});
update_cdb_order
();
update_cdb_order
();
}
else
{
}
else
{
...
@@ -174,6 +192,51 @@ function compute_products_coverage_qties() {
...
@@ -174,6 +192,51 @@ function compute_products_coverage_qties() {
}
}
}
}
/**
* Update order products data in case they have changed.
*/
function
check_products_data
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
product_ids
=
products
.
map
(
p
=>
p
.
id
);
if
(
product_ids
.
length
>
0
)
{
clicked_order_pill
.
find
(
'.pill_order_name'
).
empty
().
append
(
`<i class="fas fa-spinner fa-spin"></i>`
);
$
.
ajax
({
type
:
'POST'
,
url
:
'/products/get_product_for_order_helper'
,
data
:
JSON
.
stringify
(
product_ids
),
dataType
:
"json"
,
traditional
:
true
,
contentType
:
"application/json; charset=utf-8"
,
success
:
function
(
data
)
{
for
(
let
product
of
data
.
products
)
{
const
p_index
=
products
.
findIndex
(
p
=>
p
.
id
==
product
.
id
);
// Override products data with new data
products
[
p_index
]
=
{
...
products
[
p_index
],
...
product
};
}
resolve
();
},
error
:
function
(
data
)
{
err
=
{
msg
:
"erreur serveur lors de la vérification des données des articles"
,
ctx
:
'check_products_data'
};
if
(
typeof
data
.
responseJSON
!=
'undefined'
&&
typeof
data
.
responseJSON
.
error
!=
'undefined'
)
{
err
.
msg
+=
' : '
+
data
.
responseJSON
.
error
;
}
report_JS_error
(
err
,
'orders'
);
alert
(
`Erreur lors de la vérification des données des articles. Certaines données peuvent être erronées`
);
// Don't block process if this call fails
resolve
();
}
});
}
else
{
resolve
();
}
});
}
/* - SUPPLIERS */
/* - SUPPLIERS */
...
@@ -533,7 +596,8 @@ function generate_inventory() {
...
@@ -533,7 +596,8 @@ function generate_inventory() {
* Event fct: on click on an order button
* Event fct: on click on an order button
*/
*/
function
order_pill_on_click
()
{
function
order_pill_on_click
()
{
let
order_name_container
=
$
(
this
).
find
(
'.pill_order_name'
);
clicked_order_pill
=
$
(
this
);
let
order_name_container
=
clicked_order_pill
.
find
(
'.pill_order_name'
);
let
doc_id
=
$
(
order_name_container
).
text
();
let
doc_id
=
$
(
order_name_container
).
text
();
dbc
.
get
(
doc_id
).
then
((
doc
)
=>
{
dbc
.
get
(
doc_id
).
then
((
doc
)
=>
{
...
@@ -784,11 +848,12 @@ function goto_main_screen(doc) {
...
@@ -784,11 +848,12 @@ function goto_main_screen(doc) {
products
=
order_doc
.
products
;
products
=
order_doc
.
products
;
selected_suppliers
=
order_doc
.
selected_suppliers
;
selected_suppliers
=
order_doc
.
selected_suppliers
;
// TODO update products moving data (stock, qté entrante, conso moy/jour
)
check_products_data
(
)
.
then
(()
=>
{
update_cdb_order
();
update_cdb_order
();
update_main_screen
();
update_main_screen
();
switch_screen
();
switch_screen
();
})
}
}
function
back
()
{
function
back
()
{
...
@@ -1340,8 +1405,8 @@ function update_order_selection_screen() {
...
@@ -1340,8 +1405,8 @@ function update_order_selection_screen() {
$
(
".order_pill"
).
off
();
$
(
".order_pill"
).
off
();
let
existing_orders_container
=
$
(
"#existing_orders"
);
let
existing_orders_container
=
$
(
"#existing_orders"
);
existing_orders_container
.
empty
();
existing_orders_container
.
empty
();
$
(
'#new_order_name'
).
val
(
''
);
dbc
.
allDocs
({
dbc
.
allDocs
({
include_docs
:
true
include_docs
:
true
...
...
products/models.py
View file @
20c13305
...
@@ -482,7 +482,7 @@ class CagetteProducts(models.Model):
...
@@ -482,7 +482,7 @@ class CagetteProducts(models.Model):
and
(
p
[
"date_end"
]
is
False
or
p
[
"date_end"
]
is
not
False
and
p
[
"date_end"
]
>=
today
)):
and
(
p
[
"date_end"
]
is
False
or
p
[
"date_end"
]
is
not
False
and
p
[
"date_end"
]
>=
today
)):
ptids
.
append
(
p
[
"product_tmpl_id"
][
0
])
ptids
.
append
(
p
[
"product_tmpl_id"
][
0
])
else
:
else
:
ptids
=
pids
ptids
=
[
int
(
x
)
for
x
in
pids
]
# Get products templates
# Get products templates
f
=
[
f
=
[
...
@@ -507,8 +507,6 @@ class CagetteProducts(models.Model):
...
@@ -507,8 +507,6 @@ class CagetteProducts(models.Model):
#'to': '2019-08-10',
#'to': '2019-08-10',
}
}
sales
=
CagetteProducts
.
get_template_products_sales_average
(
sales_average_params
)
sales
=
CagetteProducts
.
get_template_products_sales_average
(
sales_average_params
)
print
(
'---- ptids'
)
print
(
ptids
)
if
'list'
in
sales
and
len
(
sales
[
'list'
])
>
0
:
if
'list'
in
sales
and
len
(
sales
[
'list'
])
>
0
:
sales
=
sales
[
'list'
]
sales
=
sales
[
'list'
]
...
...
products/urls.py
View file @
20c13305
...
@@ -5,7 +5,7 @@ from . import views
...
@@ -5,7 +5,7 @@ from . import views
urlpatterns
=
[
urlpatterns
=
[
url
(
r'^$'
,
views
.
home
),
url
(
r'^$'
,
views
.
home
),
url
(
r'^simple_list$'
,
views
.
get_simple_list
),
url
(
r'^simple_list$'
,
views
.
get_simple_list
),
url
(
r'^get_product_for_order_helper
/([0-9]+)
$'
,
views
.
get_product_for_order_helper
),
url
(
r'^get_product_for_order_helper$'
,
views
.
get_product_for_order_helper
),
url
(
r'^get_product_data$'
,
views
.
get_product_data
),
url
(
r'^get_product_data$'
,
views
.
get_product_data
),
url
(
r'^get_products_stdprices$'
,
views
.
get_products_stdprices
),
url
(
r'^get_products_stdprices$'
,
views
.
get_products_stdprices
),
url
(
r'^update_product_stock$'
,
views
.
update_product_stock
),
url
(
r'^update_product_stock$'
,
views
.
update_product_stock
),
...
...
products/views.py
View file @
20c13305
...
@@ -39,12 +39,11 @@ def get_simple_list(request):
...
@@ -39,12 +39,11 @@ def get_simple_list(request):
return
JsonResponse
(
res
,
safe
=
False
)
return
JsonResponse
(
res
,
safe
=
False
)
def
get_product_for_order_helper
(
request
,
tpl_id
):
def
get_product_for_order_helper
(
request
):
res
=
{}
res
=
{}
try
:
try
:
result
=
CagetteProducts
.
get_products_for_order_helper
(
None
,
[
int
(
tpl_id
)])
pids
=
json
.
loads
(
request
.
body
.
decode
())
if
len
(
result
[
"products"
])
==
1
:
res
=
CagetteProducts
.
get_products_for_order_helper
(
None
,
pids
)
res
=
result
[
"products"
][
0
]
except
Exception
as
e
:
except
Exception
as
e
:
coop_logger
.
error
(
"get_product_for_help_order_line :
%
s"
,
str
(
e
))
coop_logger
.
error
(
"get_product_for_help_order_line :
%
s"
,
str
(
e
))
res
[
'error'
]
=
str
(
e
)
res
[
'error'
]
=
str
(
e
)
...
...
templates/orders/helper.html
View file @
20c13305
...
@@ -30,10 +30,10 @@
...
@@ -30,10 +30,10 @@
</div>
</div>
<div
id=
"main_content"
class=
"page_content"
style=
"display:none;"
>
<div
id=
"main_content"
class=
"page_content"
style=
"display:none;"
>
<div
id=
"back_to_order_selection_from_main
"
>
<div
class=
"actions_buttons_area
"
>
<button
type=
"button"
class=
"btn--danger"
><i
class=
"fas fa-arrow-left"
></i>
Retour
</button
>
<button
type=
"button"
class=
"btn--danger"
id=
"back_to_order_selection_from_main"
>
</div>
<i
class=
"fas fa-arrow-left"
></i>
Retour
<div
id=
"actions_buttons_area"
>
</button
>
<button
type=
"button"
class=
'btn--primary'
id=
"do_inventory"
style=
"display:none;"
>
<button
type=
"button"
class=
'btn--primary'
id=
"do_inventory"
style=
"display:none;"
>
Faire un inventaire
Faire un inventaire
</button>
</button>
...
@@ -80,8 +80,10 @@
...
@@ -80,8 +80,10 @@
</div>
</div>
<div
id=
"orders_created"
class=
"page_content"
style=
"display:none;"
>
<div
id=
"orders_created"
class=
"page_content"
style=
"display:none;"
>
<div
id=
"back_to_order_selection_from_orders_created"
>
<div
class=
"actions_buttons_area"
>
<button
type=
"button"
class=
"btn--danger"
><i
class=
"fas fa-arrow-left"
></i>
Retour
</button>
<button
type=
"button"
class=
"btn--danger"
id=
"back_to_order_selection_from_orders_created"
>
<i
class=
"fas fa-arrow-left"
></i>
Retour
</button>
</div>
</div>
<div
class=
"order_created_header txtcenter"
>
<div
class=
"order_created_header txtcenter"
>
<h2>
Commandes créées !
</h2>
<h2>
Commandes créées !
</h2>
...
...
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