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
faded170
Commit
faded170
authored
Jul 30, 2021
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
set an end date to supplier-product association instead of removing it
parent
7cea0713
Pipeline
#1264
passed with stage
in 1 minute 22 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
31 deletions
+49
-31
models.py
orders/models.py
+1
-1
orders_helper.js
orders/static/js/orders_helper.js
+10
-9
urls.py
orders/urls.py
+1
-1
views.py
orders/views.py
+15
-13
models.py
products/models.py
+21
-6
helper.html
templates/orders/helper.html
+1
-1
No files found.
orders/models.py
View file @
faded170
...
...
@@ -259,7 +259,7 @@ class Order(models.Model):
for
line
in
order_lines
:
product_line_name
=
line
[
"name"
]
if
line
[
"product_code"
]
is
not
False
:
if
"product_code"
in
line
and
line
[
"product_code"
]
is
not
False
:
product_code
=
str
(
line
[
"product_code"
])
product_line_name
=
f
"[{product_code}] {product_line_name}"
...
...
orders/static/js/orders_helper.js
View file @
faded170
...
...
@@ -497,6 +497,7 @@ function save_supplier_product_association(product, supplier, cell) {
product
.
suppliersinfo
.
push
({
supplier_id
:
supplier
.
id
,
package_qty
:
package_qty
,
product_code
:
false
,
price
:
price
});
...
...
@@ -539,7 +540,7 @@ function save_supplier_product_association(product, supplier, cell) {
* @param {object} product
* @param {object} supplier
*/
function
remove
_supplier_product_association
(
product
,
supplier
)
{
function
end
_supplier_product_association
(
product
,
supplier
)
{
openModal
();
const
data
=
{
...
...
@@ -550,7 +551,7 @@ function remove_supplier_product_association(product, supplier) {
// Send request to create association
$
.
ajax
({
type
:
"POST"
,
url
:
"/orders/
remove
_supplier_product_association"
,
url
:
"/orders/
end
_supplier_product_association"
,
dataType
:
"json"
,
traditional
:
true
,
contentType
:
"application/json; charset=utf-8"
,
...
...
@@ -572,7 +573,7 @@ function remove_supplier_product_association(product, supplier) {
let
msg
=
"erreur serveur lors de la suppression de l'association product/supplier"
.
msg
+=
` (product_tmpl_id:
${
product
.
id
}
; supplier_id:
${
supplier
.
id
}
)`
;
err
=
{
msg
:
msg
,
ctx
:
'
remove
_supplier_product_association'
};
err
=
{
msg
:
msg
,
ctx
:
'
end
_supplier_product_association'
};
if
(
typeof
data
.
responseJSON
!=
'undefined'
&&
typeof
data
.
responseJSON
.
error
!=
'undefined'
)
{
err
.
msg
+=
' : '
+
data
.
responseJSON
.
error
;
}
...
...
@@ -1541,20 +1542,20 @@ function display_products(params) {
const
supplier_id
=
id_split
[
3
];
if
(
val
==
-
1
)
{
let
modal_
remove_supplier_product_association
=
$
(
'#templates #modal_remove
_supplier_product_association'
);
let
modal_
end_supplier_product_association
=
$
(
'#templates #modal_end
_supplier_product_association'
);
const
product
=
products
.
find
(
p
=>
p
.
id
==
prod_id
);
modal_
remove
_supplier_product_association
.
find
(
".product_name"
).
text
(
product
.
name
);
modal_
end
_supplier_product_association
.
find
(
".product_name"
).
text
(
product
.
name
);
const
supplier
=
selected_suppliers
.
find
(
s
=>
s
.
id
==
supplier_id
);
modal_
remove
_supplier_product_association
.
find
(
".supplier_name"
).
text
(
supplier
.
display_name
);
modal_
end
_supplier_product_association
.
find
(
".supplier_name"
).
text
(
supplier
.
display_name
);
openModal
(
modal_
remove
_supplier_product_association
.
html
(),
modal_
end
_supplier_product_association
.
html
(),
()
=>
{
if
(
is_time_to
(
'validate_
remove
_supplier_product_association'
))
{
remove
_supplier_product_association
(
product
,
supplier
);
if
(
is_time_to
(
'validate_
end
_supplier_product_association'
))
{
end
_supplier_product_association
(
product
,
supplier
);
}
},
'Valider'
,
...
...
orders/urls.py
View file @
faded170
...
...
@@ -13,7 +13,7 @@ urlpatterns = [
url
(
r'^get_suppliers$'
,
views
.
get_suppliers
),
url
(
r'^get_supplier_products$'
,
views
.
get_supplier_products
),
url
(
r'^associate_supplier_to_product$'
,
views
.
associate_supplier_to_product
),
url
(
r'^
remove_supplier_product_association$'
,
views
.
remove
_supplier_product_association
),
url
(
r'^
end_supplier_product_association$'
,
views
.
end
_supplier_product_association
),
url
(
r'^create_orders$'
,
views
.
create_orders
),
url
(
r'^get_orders_attachment$'
,
views
.
get_orders_attachment
),
]
orders/views.py
View file @
faded170
...
...
@@ -54,26 +54,28 @@ def get_supplier_products(request):
def
associate_supplier_to_product
(
request
):
""" This product is now supplied by this supplier """
res
=
{}
try
:
data
=
json
.
loads
(
request
.
body
.
decode
())
res
=
CagetteProduct
.
associate_supplier_to_product
(
data
)
except
Exception
as
e
:
res
[
"error"
]
=
str
(
e
)
data
=
json
.
loads
(
request
.
body
.
decode
())
res
=
CagetteProduct
.
associate_supplier_to_product
(
data
)
if
'error'
in
res
:
return
JsonResponse
(
res
,
status
=
500
)
else
:
return
JsonResponse
({
'res'
:
res
})
return
JsonResponse
({
'res'
:
res
})
def
remove
_supplier_product_association
(
request
):
def
end
_supplier_product_association
(
request
):
""" This product is now unavailable from this supplier """
res
=
{}
try
:
data
=
json
.
loads
(
request
.
body
.
decode
())
res
=
CagetteProduct
.
remove_supplier_product_association
(
data
)
except
Exception
as
e
:
res
[
"error"
]
=
str
(
e
)
return
JsonResponse
(
res
,
status
=
500
)
return
JsonResponse
({
'res'
:
res
})
data
=
json
.
loads
(
request
.
body
.
decode
())
res
=
CagetteProduct
.
end_supplier_product_association
(
data
)
if
'error'
in
res
:
return
JsonResponse
(
res
,
status
=
500
)
else
:
return
JsonResponse
({
'res'
:
res
})
def
create_orders
(
request
):
""" Create products orders """
...
...
products/models.py
View file @
faded170
...
...
@@ -141,6 +141,8 @@ class CagetteProduct(models.Model):
c
=
[[
'product_tmpl_id'
,
'='
,
product_tmpl_id
]]
res_products
=
api
.
search_read
(
'product.product'
,
c
,
f
)
product
=
res_products
[
0
]
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
f
=
{
'product_tmpl_id'
:
product_tmpl_id
,
...
...
@@ -150,29 +152,40 @@ class CagetteProduct(models.Model):
'price'
:
price
,
'base_price'
:
price
,
'package_qty'
:
package_qty
,
'date_start'
:
today
,
'sequence'
:
1000
# lowest priority for the new suppliers
}
try
:
res
=
api
.
create
(
'product.supplierinfo'
,
f
)
res
[
'create'
]
=
api
.
create
(
'product.supplierinfo'
,
f
)
except
Exception
as
e
:
res
[
'error'
]
=
str
(
e
)
return
res
@staticmethod
def
remove
_supplier_product_association
(
data
):
def
end
_supplier_product_association
(
data
):
api
=
OdooAPI
()
res
=
{}
product_tmpl_id
=
data
[
"product_tmpl_id"
]
partner_id
=
data
[
"supplier_id"
]
f
=
[
"id"
]
c
=
[[
'product_tmpl_id'
,
'='
,
product_tmpl_id
],
[
'name'
,
'='
,
partner_id
]]
c
=
[[
'product_tmpl_id'
,
'='
,
product_tmpl_id
],
[
'name'
,
'='
,
partner_id
]
,
[
'date_end'
,
'='
,
False
]
]
res_supplierinfo
=
api
.
search_read
(
'product.supplierinfo'
,
c
,
f
)
psi_id
=
res_supplierinfo
[
0
][
'id'
]
res
=
api
.
execute
(
'product.supplierinfo'
,
'unlink'
,
[
psi_id
])
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
f
=
{
'date_end'
:
today
}
try
:
res
[
"update"
]
=
api
.
update
(
'product.supplierinfo'
,
psi_id
,
f
)
except
Exception
as
e
:
res
[
'error'
]
=
str
(
e
)
return
res
...
...
@@ -514,10 +527,12 @@ class CagetteProducts(models.Model):
# Filter valid data
ptids
=
[]
valid_psi
=
[]
for
p
in
psi
:
if
(
p
[
"product_tmpl_id"
]
is
not
False
and
(
p
[
"date_start"
]
is
False
or
p
[
"date_start"
]
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
)):
valid_psi
.
append
(
p
)
ptids
.
append
(
p
[
"product_tmpl_id"
][
0
])
else
:
ptids
=
[
int
(
x
)
for
x
in
pids
]
...
...
@@ -560,7 +575,7 @@ class CagetteProducts(models.Model):
if
supplier_ids
is
not
None
and
len
(
supplier_ids
)
>
0
:
# Add all the product suppliersinfo (products from multiple suppliers into the suppliers list provided)
filtered_products_t
[
i
][
'suppliersinfo'
]
=
[]
for
psi_item
in
psi
:
for
psi_item
in
valid_
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
]),
...
...
templates/orders/helper.html
View file @
faded170
...
...
@@ -246,7 +246,7 @@
<hr/>
</div>
<div
id=
"modal_
remove
_supplier_product_association"
>
<div
id=
"modal_
end
_supplier_product_association"
>
<h3>
Attention !
</h3>
<p>
Vous vous apprêtez à rendre le produit
<span
class=
"product_name"
></span>
...
...
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