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() {
for
(
let
product
of
data
.
res
.
products
)
{
const
p_index
=
products
.
findIndex
(
p
=>
p
.
id
==
product
.
id
);
// Override products data with new data (without suppliersinfo so we don't override qty)
const
updated_suppliersinfo
=
product
.
suppliersinfo
;
if
(
p_index
===
-
1
)
{
// 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
;
products
[
p_index
]
=
{
...
products
[
p_index
],
...
product
}
;
// Update product data
products
[
p_index
]
=
product
;
// Update suppliers info
// Re-set qties
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
)
{
products
[
p_index
].
suppliersinfo
[
psi_index
].
package_qty
=
updated_psi
.
package_
qty
;
products
[
p_index
].
suppliersinfo
[
psi_index
].
price
=
updated_psi
.
price
;
if
(
old_psi
!==
undefined
&&
old_psi
.
qty
!==
undefined
)
{
products
[
p_index
].
suppliersinfo
[
psi_index
].
qty
=
old_psi
.
qty
;
}
}
}
}
...
...
@@ -435,11 +438,13 @@ function save_supplier_products(supplier, new_products) {
if
(
index
===
-
1
)
{
products
.
push
(
np
);
}
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
);
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
);
}
}
...
...
@@ -1335,6 +1340,7 @@ function display_products(params) {
const
product
=
products
.
find
(
p
=>
p
.
id
==
prod_id
);
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
)
.
draw
();
...
...
products/models.py
View file @
307d0490
...
...
@@ -465,7 +465,6 @@ class CagetteProducts(models.Model):
api
=
OdooAPI
()
res
=
{}
# todo : try with no result
try
:
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
...
...
@@ -517,12 +516,15 @@ class CagetteProducts(models.Model):
# Add supplier data to product data
for
i
,
fp
in
enumerate
(
filtered_products_t
):
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"
])
filtered_products_t
[
i
][
'suppliersinfo'
]
=
[{
# Add all the product suppliersinfo (products from multiple suppliers into the suppliers list provided)
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
]),
'package_qty'
:
psi_item
[
"package_qty"
],
'price'
:
psi_item
[
"price"
]
}]
})
for
s
in
sales
:
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