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
1fa5625a
Commit
1fa5625a
authored
Jul 01, 2021
by
Damien Moulard
Committed by
Alexis Aoun
Jul 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update suppliers info at product info check
parent
37eeb8b7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
34 deletions
+31
-34
orders_helper.js
orders/static/js/orders_helper.js
+19
-22
views.py
orders/views.py
+2
-2
models.py
products/models.py
+10
-10
No files found.
orders/static/js/orders_helper.js
View file @
1fa5625a
...
...
@@ -112,19 +112,6 @@ function add_product() {
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({
type: 'POST',
url: '/products/get_product_for_order_helper',
data: JSON.stringify(product_ids),
dataType:"json",
*/
$
.
ajax
({
type
:
'POST'
,
url
:
'/products/get_product_for_order_helper'
,
...
...
@@ -194,9 +181,9 @@ function compute_products_coverage_qties() {
*/
function
check_products_data
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
product_ids
=
products
.
map
(
p
=>
p
.
id
);
const
suppliers_id
=
selected_suppliers
.
map
(
s
=>
s
.
id
);
if
(
product_ids
.
length
>
0
)
{
if
(
suppliers_id
.
length
>
0
)
{
$
.
notify
(
"Vérfication des informations produits..."
,
{
...
...
@@ -208,18 +195,29 @@ function check_products_data() {
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
),
type
:
'GET'
,
url
:
'/orders/get_supplier_products'
,
data
:
{
sids
:
suppliers_id
},
dataType
:
"json"
,
traditional
:
true
,
contentType
:
"application/json; charset=utf-8"
,
success
:
function
(
data
)
{
for
(
let
product
of
data
.
products
)
{
for
(
let
product
of
data
.
res
.
products
)
{
const
p_index
=
products
.
findIndex
(
p
=>
p
.
id
==
product
.
id
);
// Override products data with new data
// Override products data with new data (without suppliersinfo so we don't override qty)
const
updated_suppliersinfo
=
product
.
suppliersinfo
;
delete
product
.
suppliersinfo
;
products
[
p_index
]
=
{
...
products
[
p_index
],
...
product
};
// Update suppliers info
for
(
let
psi_index
in
products
[
p_index
].
suppliersinfo
)
{
const
updated_psi
=
updated_suppliersinfo
.
find
(
psi
=>
psi
.
supplier_id
==
products
[
p_index
].
suppliersinfo
[
psi_index
].
supplier_id
);
products
[
p_index
].
suppliersinfo
[
psi_index
].
package_qty
=
updated_psi
.
package_qty
;
products
[
p_index
].
suppliersinfo
[
psi_index
].
price
=
updated_psi
.
price
;
}
}
$
(
'.notifyjs-wrapper'
).
trigger
(
'notify-hide'
);
...
...
@@ -278,8 +276,7 @@ function add_supplier() {
selected_suppliers
.
push
(
supplier
);
let
url
=
"/orders/get_supplier_products"
;
url
+=
"?sid="
+
encodeURIComponent
(
supplier
.
id
);
url
+=
"?sids="
+
encodeURIComponent
(
supplier
.
id
);
// Fetch supplier products
$
.
ajax
({
...
...
orders/views.py
View file @
1fa5625a
...
...
@@ -41,8 +41,8 @@ def get_suppliers(request):
def
get_supplier_products
(
request
):
""" Get supplier products """
s
id
=
request
.
GET
.
get
(
'sid
'
,
''
)
res
=
CagetteProducts
.
get_products_for_order_helper
(
sid
)
s
uppliers_id
=
request
.
GET
.
getlist
(
'sids
'
,
''
)
res
=
CagetteProducts
.
get_products_for_order_helper
(
s
uppliers_
id
)
if
'error'
in
res
:
return
JsonResponse
(
res
,
status
=
500
)
...
...
products/models.py
View file @
1fa5625a
...
...
@@ -455,11 +455,11 @@ class CagetteProducts(models.Model):
return
res
@staticmethod
def
get_products_for_order_helper
(
supplier_id
,
pids
=
[]):
def
get_products_for_order_helper
(
supplier_id
s
,
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
.
One of the two parameters must be
not empty
.
Get products by supplier if
one or more
supplier_id is set.
If supplier_id
s is empty, get products specified in pids. In this case, suppliers info won't be fetched
.
"""
api
=
OdooAPI
()
res
=
{}
...
...
@@ -468,10 +468,10 @@ class CagetteProducts(models.Model):
try
:
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
if
supplier_id
is
not
None
:
if
len
(
supplier_ids
)
>
0
:
# Get products/supplier relation
f
=
[
"product_tmpl_id"
,
'date_start'
,
'date_end'
,
'package_qty'
,
'price'
]
c
=
[[
'name'
,
'
='
,
int
(
supplier_id
)
]]
f
=
[
"product_tmpl_id"
,
'date_start'
,
'date_end'
,
'package_qty'
,
'price'
,
'name'
]
c
=
[[
'name'
,
'
in'
,
[
int
(
x
)
for
x
in
supplier_ids
]
]]
psi
=
api
.
search_read
(
'product.supplierinfo'
,
c
,
f
)
# Filter valid data
...
...
@@ -515,10 +515,10 @@ class CagetteProducts(models.Model):
# Add supplier data to product data
for
i
,
fp
in
enumerate
(
filtered_products_t
):
if
supplier_id
is
not
None
:
if
len
(
supplier_ids
)
>
0
:
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'
]
=
[{
'supplier_id'
:
int
(
supplier_id
),
'supplier_id'
:
int
(
psi_item
[
"name"
][
0
]
),
'package_qty'
:
psi_item
[
"package_qty"
],
'price'
:
psi_item
[
"price"
]
}]
...
...
@@ -531,7 +531,7 @@ class CagetteProducts(models.Model):
res
[
"products"
]
=
filtered_products_t
except
Exception
as
e
:
coop_logger
.
error
(
'get_products_for_order_helper
%
s (
%
s)'
,
str
(
e
)
,
str
(
supplier_id
)
)
coop_logger
.
error
(
'get_products_for_order_helper
%
s (
%
s)'
,
str
(
e
))
res
[
"error"
]
=
str
(
e
)
return
res
...
...
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