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
307d0490
Commit
307d0490
authored
Jul 23, 2021
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AAC: on products data checkup, add new products & update suppliers info
parent
eff4f693
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
16 deletions
+24
-16
orders_helper.js
orders/static/js/orders_helper.js
+18
-12
models.py
products/models.py
+6
-4
No files found.
orders/static/js/orders_helper.js
View file @
307d0490
...
@@ -208,21 +208,24 @@ function check_products_data() {
...
@@ -208,21 +208,24 @@ function check_products_data() {
for
(
let
product
of
data
.
res
.
products
)
{
for
(
let
product
of
data
.
res
.
products
)
{
const
p_index
=
products
.
findIndex
(
p
=>
p
.
id
==
product
.
id
);
const
p_index
=
products
.
findIndex
(
p
=>
p
.
id
==
product
.
id
);
// Override products data with new data (without suppliersinfo so we don't override qty)
if
(
p_index
===
-
1
)
{
const
updated_suppliersinfo
=
product
.
suppliersinfo
;
// Add product if it wasn't fetched before (made available since last access to order)
products
.
push
(
product
);
}
else
{
// Save old product suppliersinfo to keep user qty inputs
const
old_suppliersinfo
=
[
...
products
[
p_index
].
suppliersinfo
];
delete
product
.
suppliersinfo
;
// Update product data
products
[
p_index
]
=
{
...
products
[
p_index
],
...
product
}
;
products
[
p_index
]
=
product
;
// Update suppliers info
// Re-set qties
for
(
let
psi_index
in
products
[
p_index
].
suppliersinfo
)
{
for
(
let
psi_index
in
products
[
p_index
].
suppliersinfo
)
{
const
updated_psi
=
update
d_suppliersinfo
.
find
(
psi
=>
psi
.
supplier_id
==
products
[
p_index
].
suppliersinfo
[
psi_index
].
supplier_id
);
const
old_psi
=
ol
d_suppliersinfo
.
find
(
psi
=>
psi
.
supplier_id
==
products
[
p_index
].
suppliersinfo
[
psi_index
].
supplier_id
);
if
(
updated_psi
!==
undefined
)
{
if
(
old_psi
!==
undefined
&&
old_psi
.
qty
!==
undefined
)
{
products
[
p_index
].
suppliersinfo
[
psi_index
].
package_qty
=
updated_psi
.
package_
qty
;
products
[
p_index
].
suppliersinfo
[
psi_index
].
qty
=
old_psi
.
qty
;
products
[
p_index
].
suppliersinfo
[
psi_index
].
price
=
updated_psi
.
price
;
}
}
}
}
}
}
}
...
@@ -435,11 +438,13 @@ function save_supplier_products(supplier, new_products) {
...
@@ -435,11 +438,13 @@ function save_supplier_products(supplier, new_products) {
if
(
index
===
-
1
)
{
if
(
index
===
-
1
)
{
products
.
push
(
np
);
products
.
push
(
np
);
}
else
{
}
else
{
// Prevent adding du
c
plicate supplierinfo
// Prevent adding duplicate supplierinfo
let
index_existing_supplierinfo
=
products
[
index
].
suppliersinfo
.
findIndex
(
psi
=>
psi
.
supplier_id
==
supplier
.
id
);
let
index_existing_supplierinfo
=
products
[
index
].
suppliersinfo
.
findIndex
(
psi
=>
psi
.
supplier_id
==
supplier
.
id
);
if
(
index_existing_supplierinfo
===
-
1
)
{
if
(
index_existing_supplierinfo
===
-
1
)
{
np_supplierinfo
=
np
.
suppliersinfo
[
0
];
// Find the right supplierinfo in new product
let
np_supplierinfo
=
np
.
suppliersinfo
.
find
(
psi
=>
psi
.
supplier_id
==
supplier
.
id
);
products
[
index
].
suppliersinfo
.
push
(
np_supplierinfo
);
products
[
index
].
suppliersinfo
.
push
(
np_supplierinfo
);
}
}
}
}
...
@@ -1335,6 +1340,7 @@ function display_products(params) {
...
@@ -1335,6 +1340,7 @@ function display_products(params) {
const
product
=
products
.
find
(
p
=>
p
.
id
==
prod_id
);
const
product
=
products
.
find
(
p
=>
p
.
id
==
prod_id
);
const
new_row_data
=
prepare_datatable_data
([
product
.
id
])[
0
];
const
new_row_data
=
prepare_datatable_data
([
product
.
id
])[
0
];
// TODO erreur console après ajout d'un fournisseur
products_table
.
row
(
$
(
this
).
closest
(
'tr'
)).
data
(
new_row_data
)
products_table
.
row
(
$
(
this
).
closest
(
'tr'
)).
data
(
new_row_data
)
.
draw
();
.
draw
();
...
...
products/models.py
View file @
307d0490
...
@@ -465,7 +465,6 @@ class CagetteProducts(models.Model):
...
@@ -465,7 +465,6 @@ class CagetteProducts(models.Model):
api
=
OdooAPI
()
api
=
OdooAPI
()
res
=
{}
res
=
{}
# todo : try with no result
try
:
try
:
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
...
@@ -517,12 +516,15 @@ class CagetteProducts(models.Model):
...
@@ -517,12 +516,15 @@ 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_ids
is
not
None
and
len
(
supplier_ids
)
>
0
:
if
supplier_ids
is
not
None
and
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"
])
# Add all the product suppliersinfo (products from multiple suppliers into the suppliers list provided)
filtered_products_t
[
i
][
'suppliersinfo'
]
=
[{
filtered_products_t
[
i
][
'suppliersinfo'
]
=
[]
for
psi_item
in
psi
:
if
psi_item
[
"product_tmpl_id"
]
is
not
False
and
psi_item
[
"product_tmpl_id"
][
0
]
==
fp
[
"id"
]:
filtered_products_t
[
i
][
'suppliersinfo'
]
.
append
({
'supplier_id'
:
int
(
psi_item
[
"name"
][
0
]),
'supplier_id'
:
int
(
psi_item
[
"name"
][
0
]),
'package_qty'
:
psi_item
[
"package_qty"
],
'package_qty'
:
psi_item
[
"package_qty"
],
'price'
:
psi_item
[
"price"
]
'price'
:
psi_item
[
"price"
]
}]
})
for
s
in
sales
:
for
s
in
sales
:
if
s
[
"id"
]
==
fp
[
"id"
]:
if
s
[
"id"
]
==
fp
[
"id"
]:
...
...
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