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
53a5e9dc
Commit
53a5e9dc
authored
Jun 30, 2021
by
Damien Moulard
Committed by
Alexis Aoun
Jul 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AAC: fix fetch one product
parent
69c391c7
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
38 deletions
+36
-38
oders_helper_style.css
orders/static/css/oders_helper_style.css
+7
-0
orders_helper.js
orders/static/js/orders_helper.js
+8
-16
views.py
orders/views.py
+1
-1
models.py
products/models.py
+15
-16
urls.py
products/urls.py
+1
-1
views.py
products/views.py
+4
-4
No files found.
orders/static/css/oders_helper_style.css
View file @
53a5e9dc
...
@@ -115,6 +115,13 @@
...
@@ -115,6 +115,13 @@
margin-left
:
5px
;
margin-left
:
5px
;
}
}
.custom_cell_content
{
display
:
flex
;
flex-direction
:
column
;
justify-content
:
center
;
align-items
:
center
;
}
.product_qty_input
{
.product_qty_input
{
width
:
100px
;
width
:
100px
;
}
}
...
...
orders/static/js/orders_helper.js
View file @
53a5e9dc
...
@@ -101,7 +101,7 @@ function add_product() {
...
@@ -101,7 +101,7 @@ function add_product() {
}
}
$
.
ajax
({
$
.
ajax
({
type
:
'GET'
,
type
:
'GET'
,
url
:
'/products/get_product_for_
help_order_line
/'
+
product
.
tpl_id
,
url
:
'/products/get_product_for_
order_helper
/'
+
product
.
tpl_id
,
dataType
:
"json"
,
dataType
:
"json"
,
traditional
:
true
,
traditional
:
true
,
contentType
:
"application/json; charset=utf-8"
,
contentType
:
"application/json; charset=utf-8"
,
...
@@ -556,7 +556,7 @@ function order_pill_on_click() {
...
@@ -556,7 +556,7 @@ function order_pill_on_click() {
className
:
"error"
className
:
"error"
}
}
);
);
update_order_selection_screen
()
update_order_selection_screen
()
;
}
else
{
}
else
{
alert
(
'Erreur lors de la récupération de la commande. Si l
\'
erreur persiste, contactez un administrateur svp.'
);
alert
(
'Erreur lors de la récupération de la commande. Si l
\'
erreur persiste, contactez un administrateur svp.'
);
}
}
...
@@ -848,12 +848,12 @@ function _compute_product_data(product) {
...
@@ -848,12 +848,12 @@ function _compute_product_data(product) {
}
}
}
}
if
(
p_package_qties
.
every
(
(
val
,
i
,
arr
)
=>
val
===
arr
[
0
]
))
{
if
(
p_package_qties
.
length
==
0
||
!
p_package_qties
.
every
(
(
val
,
i
,
arr
)
=>
val
===
arr
[
0
]
))
{
// Don't display package qty if no supplierinf or if not all package qties are equals,
item
.
package_qty
=
'X'
;
}
else
{
// If all package qties are equals, display it
// If all package qties are equals, display it
item
.
package_qty
=
p_package_qties
[
0
];
item
.
package_qty
=
p_package_qties
[
0
];
}
else
{
// Else display an X
item
.
package_qty
=
'X'
;
}
}
/* Coverage related data */
/* Coverage related data */
...
@@ -981,9 +981,9 @@ function prepare_datatable_columns() {
...
@@ -981,9 +981,9 @@ function prepare_datatable_columns() {
const
base_id
=
`product_
${
full
.
id
}
_supplier_
${
supplier
.
id
}
`
;
const
base_id
=
`product_
${
full
.
id
}
_supplier_
${
supplier
.
id
}
`
;
if
(
data
===
false
)
{
if
(
data
===
false
)
{
return
`<div id="
${
base_id
}
_cell_content" class="cell_content">X</div>`
;
return
`<div id="
${
base_id
}
_cell_content" class="c
ustom_c
ell_content">X</div>`
;
}
else
{
}
else
{
let
content
=
`<div id="
${
base_id
}
_cell_content" class="cell_content">
let
content
=
`<div id="
${
base_id
}
_cell_content" class="c
ustom_c
ell_content">
<input type="number" class="product_qty_input" id="
${
base_id
}
_qty_input" min="0" value=
${
data
}
>`
;
<input type="number" class="product_qty_input" id="
${
base_id
}
_qty_input" min="0" value=
${
data
}
>`
;
if
(
full
.
package_qty
===
'X'
)
{
if
(
full
.
package_qty
===
'X'
)
{
...
@@ -1005,14 +1005,6 @@ function prepare_datatable_columns() {
...
@@ -1005,14 +1005,6 @@ function prepare_datatable_columns() {
data
:
"package_qty"
,
data
:
"package_qty"
,
title
:
"Colisage"
,
title
:
"Colisage"
,
className
:
"dt-body-center"
,
className
:
"dt-body-center"
,
render
:
(
data
,
type
,
full
)
=>
{
if
(
full
.
package_qty
===
'X'
)
{
return
'<div class="tooltip">'
+
data
+
' <span class="tooltiptext tt_twolines">Colisages différents !</span></div>'
}
else
{
return
data
;
}
},
width
:
"4%"
width
:
"4%"
});
});
...
...
orders/views.py
View file @
53a5e9dc
...
@@ -42,7 +42,7 @@ def get_supplier_products(request):
...
@@ -42,7 +42,7 @@ def get_supplier_products(request):
""" Get supplier products """
""" Get supplier products """
sid
=
request
.
GET
.
get
(
'sid'
,
''
)
sid
=
request
.
GET
.
get
(
'sid'
,
''
)
res
=
CagetteProducts
.
get_products_
by_suppli
er
(
sid
)
res
=
CagetteProducts
.
get_products_
for_order_help
er
(
sid
)
if
'error'
in
res
:
if
'error'
in
res
:
return
JsonResponse
(
res
,
status
=
500
)
return
JsonResponse
(
res
,
status
=
500
)
...
...
products/models.py
View file @
53a5e9dc
...
@@ -171,19 +171,6 @@ class CagetteProduct(models.Model):
...
@@ -171,19 +171,6 @@ class CagetteProduct(models.Model):
return
res
return
res
@staticmethod
def
get_product_for_help_order_line
(
product_tmpl_id
):
api
=
OdooAPI
()
res
=
[]
try
:
f
=
[
"id"
,
"state"
,
"name"
,
"default_code"
,
"qty_available"
,
"incoming_qty"
,
"uom_id"
,
"purchase_ok"
]
# TODO fetch only 'purchase_ok' products ?
c
=
[[
'id'
,
'='
,
product_tmpl_id
],
[
'purchase_ok'
,
'='
,
True
]]
products_t
=
api
.
search_read
(
'product.template'
,
c
,
f
)
res
=
[
p
for
p
in
products_t
if
p
[
"state"
]
!=
"end"
and
p
[
"state"
]
!=
"obsolete"
]
except
Exception
as
e
:
coop_logger
.
error
(
"Odoo API get_product_for_help_order_line (tpl_id =
%
s) :
%
s"
,
str
(
product_tmpl_id
),
str
(
e
))
return
res
class
CagetteProducts
(
models
.
Model
):
class
CagetteProducts
(
models
.
Model
):
"""Initially used to make massive barcode update."""
"""Initially used to make massive barcode update."""
...
@@ -468,7 +455,12 @@ class CagetteProducts(models.Model):
...
@@ -468,7 +455,12 @@ class CagetteProducts(models.Model):
return
res
return
res
@staticmethod
@staticmethod
def
get_products_by_supplier
(
supplier_id
):
def
get_products_for_order_helper
(
supplier_id
,
pids
=
[]):
"""
One of the two parameters must be set.
Get products by supplier if a supplier_id is set.
If supplier_id is None, get products specified in pids.
"""
api
=
OdooAPI
()
api
=
OdooAPI
()
res
=
{}
res
=
{}
...
@@ -476,6 +468,7 @@ class CagetteProducts(models.Model):
...
@@ -476,6 +468,7 @@ class CagetteProducts(models.Model):
try
:
try
:
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
if
supplier_id
is
not
None
:
# Get products/supplier relation
# Get products/supplier relation
f
=
[
"product_tmpl_id"
,
'date_start'
,
'date_end'
,
'package_qty'
,
'price'
]
f
=
[
"product_tmpl_id"
,
'date_start'
,
'date_end'
,
'package_qty'
,
'price'
]
c
=
[[
'name'
,
'='
,
int
(
supplier_id
)]]
c
=
[[
'name'
,
'='
,
int
(
supplier_id
)]]
...
@@ -488,6 +481,8 @@ class CagetteProducts(models.Model):
...
@@ -488,6 +481,8 @@ class CagetteProducts(models.Model):
and
(
p
[
"date_start"
]
is
False
or
p
[
"date_end"
]
is
not
False
and
p
[
"date_start"
]
<=
today
)
and
(
p
[
"date_start"
]
is
False
or
p
[
"date_end"
]
is
not
False
and
p
[
"date_start"
]
<=
today
)
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
:
ptids
=
pids
# Get products templates
# Get products templates
f
=
[
f
=
[
...
@@ -506,11 +501,14 @@ class CagetteProducts(models.Model):
...
@@ -506,11 +501,14 @@ class CagetteProducts(models.Model):
products_t
=
api
.
search_read
(
'product.template'
,
c
,
f
)
products_t
=
api
.
search_read
(
'product.template'
,
c
,
f
)
filtered_products_t
=
[
p
for
p
in
products_t
if
p
[
"state"
]
!=
"end"
and
p
[
"state"
]
!=
"obsolete"
]
filtered_products_t
=
[
p
for
p
in
products_t
if
p
[
"state"
]
!=
"end"
and
p
[
"state"
]
!=
"obsolete"
]
sales_average_params
=
{
'ids'
:
ptids
,
sales_average_params
=
{
'ids'
:
ptids
,
#'from': '2019-06-10',
#'from': '2019-06-10',
#'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'
]
...
@@ -519,6 +517,7 @@ class CagetteProducts(models.Model):
...
@@ -519,6 +517,7 @@ class CagetteProducts(models.Model):
# Add supplier data to product data
# Add supplier data to product data
for
i
,
fp
in
enumerate
(
filtered_products_t
):
for
i
,
fp
in
enumerate
(
filtered_products_t
):
if
supplier_id
is
not
None
:
psi_item
=
next
(
item
for
item
in
psi
if
item
[
"product_tmpl_id"
]
is
not
False
and
item
[
"product_tmpl_id"
][
0
]
==
fp
[
"id"
])
psi_item
=
next
(
item
for
item
in
psi
if
item
[
"product_tmpl_id"
]
is
not
False
and
item
[
"product_tmpl_id"
][
0
]
==
fp
[
"id"
])
filtered_products_t
[
i
][
'suppliersinfo'
]
=
[{
filtered_products_t
[
i
][
'suppliersinfo'
]
=
[{
'supplier_id'
:
int
(
supplier_id
),
'supplier_id'
:
int
(
supplier_id
),
...
@@ -534,7 +533,7 @@ class CagetteProducts(models.Model):
...
@@ -534,7 +533,7 @@ class CagetteProducts(models.Model):
res
[
"products"
]
=
filtered_products_t
res
[
"products"
]
=
filtered_products_t
except
Exception
as
e
:
except
Exception
as
e
:
coop_logger
.
error
(
'get_products_
by_suppli
er
%
s (
%
s)'
,
str
(
e
),
str
(
supplier_id
))
coop_logger
.
error
(
'get_products_
for_order_help
er
%
s (
%
s)'
,
str
(
e
),
str
(
supplier_id
))
res
[
"error"
]
=
str
(
e
)
res
[
"error"
]
=
str
(
e
)
return
res
return
res
...
...
products/urls.py
View file @
53a5e9dc
...
@@ -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_
help_order_line/([0-9]+)$'
,
views
.
get_product_for_help_order_line
),
url
(
r'^get_product_for_
order_helper/([0-9]+)$'
,
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 @
53a5e9dc
...
@@ -39,12 +39,12 @@ def get_simple_list(request):
...
@@ -39,12 +39,12 @@ def get_simple_list(request):
return
JsonResponse
(
res
,
safe
=
False
)
return
JsonResponse
(
res
,
safe
=
False
)
def
get_product_for_
help_order_line
(
request
,
tpl_id
):
def
get_product_for_
order_helper
(
request
,
tpl_id
):
res
=
{}
res
=
{}
try
:
try
:
result
=
CagetteProduct
.
get_product_for_help_order_line
(
tpl_id
)
result
=
CagetteProduct
s
.
get_products_for_order_helper
(
None
,
[
int
(
tpl_id
)]
)
if
len
(
result
)
==
1
:
if
len
(
result
[
"products"
]
)
==
1
:
res
=
result
[
0
]
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
)
...
...
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