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
ff8bc7e6
Commit
ff8bc7e6
authored
Aug 30, 2021
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update supplierinfo instead of creating a new onewhen reassociating
parent
8347a3c1
Pipeline
#1281
passed with stage
in 1 minute 21 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
36 deletions
+61
-36
oders_helper_style.css
orders/static/css/oders_helper_style.css
+1
-1
orders_helper.js
orders/static/js/orders_helper.js
+5
-5
models.py
products/models.py
+55
-30
No files found.
orders/static/css/oders_helper_style.css
View file @
ff8bc7e6
...
@@ -291,7 +291,7 @@
...
@@ -291,7 +291,7 @@
margin
:
30px
0
20px
0
;
margin
:
30px
0
20px
0
;
position
:
-webkit-sticky
;
position
:
-webkit-sticky
;
position
:
sticky
;
position
:
sticky
;
top
:
1
5
0px
;
top
:
1
4
0px
;
z-index
:
5
;
z-index
:
5
;
}
}
...
...
orders/static/js/orders_helper.js
View file @
ff8bc7e6
...
@@ -196,21 +196,21 @@ function compute_products_coverage_qties() {
...
@@ -196,21 +196,21 @@ function compute_products_coverage_qties() {
]
of
Object
.
entries
(
products
))
{
]
of
Object
.
entries
(
products
))
{
if
(
'suppliersinfo'
in
product
&&
product
.
suppliersinfo
.
length
>
0
)
{
if
(
'suppliersinfo'
in
product
&&
product
.
suppliersinfo
.
length
>
0
)
{
let
purchase_qty_for_coverage
=
null
;
let
purchase_qty_for_coverage
=
null
;
// Durée couverture produit = (stock + qté entrante + qté commandée ) / conso quotidienne
// Durée couverture produit = (stock + qté entrante + qté commandée ) / conso quotidienne
const
stock
=
product
.
qty_available
;
const
stock
=
product
.
qty_available
;
const
incoming_qty
=
product
.
incoming_qty
;
const
incoming_qty
=
product
.
incoming_qty
;
const
daily_conso
=
product
.
daily_conso
;
const
daily_conso
=
product
.
daily_conso
;
purchase_qty_for_coverage
=
order_doc
.
coverage_days
*
daily_conso
-
stock
-
incoming_qty
;
purchase_qty_for_coverage
=
order_doc
.
coverage_days
*
daily_conso
-
stock
-
incoming_qty
;
purchase_qty_for_coverage
=
(
purchase_qty_for_coverage
<
0
)
?
0
:
purchase_qty_for_coverage
;
purchase_qty_for_coverage
=
(
purchase_qty_for_coverage
<
0
)
?
0
:
purchase_qty_for_coverage
;
// Reduce to nb of packages to purchase
// Reduce to nb of packages to purchase
purchase_package_qty_for_coverage
=
purchase_qty_for_coverage
/
product
.
suppliersinfo
[
0
].
package_qty
;
purchase_package_qty_for_coverage
=
purchase_qty_for_coverage
/
product
.
suppliersinfo
[
0
].
package_qty
;
// Round up to unit for all products
// Round up to unit for all products
purchase_package_qty_for_coverage
=
Math
.
ceil
(
purchase_package_qty_for_coverage
);
purchase_package_qty_for_coverage
=
Math
.
ceil
(
purchase_package_qty_for_coverage
);
// Set qty to purchase for first supplier only
// Set qty to purchase for first supplier only
products
[
key
].
suppliersinfo
[
0
].
qty
=
purchase_package_qty_for_coverage
;
products
[
key
].
suppliersinfo
[
0
].
qty
=
purchase_package_qty_for_coverage
;
}
}
...
...
products/models.py
View file @
ff8bc7e6
...
@@ -136,30 +136,52 @@ class CagetteProduct(models.Model):
...
@@ -136,30 +136,52 @@ class CagetteProduct(models.Model):
partner_id
=
data
[
"supplier_id"
]
partner_id
=
data
[
"supplier_id"
]
package_qty
=
data
[
"package_qty"
]
package_qty
=
data
[
"package_qty"
]
price
=
data
[
"price"
]
price
=
data
[
"price"
]
f
=
[
"id"
,
"standard_price"
,
"purchase_ok"
]
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"
)
# Look for existing association
f
=
[
"id"
]
c
=
[[
'product_tmpl_id'
,
'='
,
product_tmpl_id
],
[
'name'
,
'='
,
partner_id
]]
res_existing_supplierinfo
=
api
.
search_read
(
'product.supplierinfo'
,
c
,
f
)
f
=
{
if
(
len
(
res_existing_supplierinfo
)
>
0
):
'product_tmpl_id'
:
product_tmpl_id
,
# A relation already exists, update it's start & end dates
'product_id'
:
product
[
"id"
],
psi_id
=
res_existing_supplierinfo
[
0
][
'id'
]
'name'
:
partner_id
,
'product_purchase_ok'
:
product
[
"purchase_ok"
],
'price'
:
price
,
'base_price'
:
price
,
'package_qty'
:
package_qty
,
'date_start'
:
today
,
'sequence'
:
1000
# lowest priority for the new suppliers
}
try
:
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
res
[
'create'
]
=
api
.
create
(
'product.supplierinfo'
,
f
)
except
Exception
as
e
:
f
=
{
res
[
'error'
]
=
str
(
e
)
'date_start'
:
today
,
'date_end'
:
False
}
try
:
res
[
"update"
]
=
api
.
update
(
'product.supplierinfo'
,
psi_id
,
f
)
except
Exception
as
e
:
res
[
'error'
]
=
str
(
e
)
else
:
# Relation doesn't exists, create one
f
=
[
"id"
,
"standard_price"
,
"purchase_ok"
]
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
,
'product_id'
:
product
[
"id"
],
'name'
:
partner_id
,
'product_purchase_ok'
:
product
[
"purchase_ok"
],
'price'
:
price
,
'base_price'
:
price
,
'package_qty'
:
package_qty
,
'date_start'
:
today
,
'sequence'
:
1000
# lowest priority for the new suppliers
}
try
:
res
[
'create'
]
=
api
.
create
(
'product.supplierinfo'
,
f
)
except
Exception
as
e
:
res
[
'error'
]
=
str
(
e
)
return
res
return
res
...
@@ -174,18 +196,21 @@ class CagetteProduct(models.Model):
...
@@ -174,18 +196,21 @@ class CagetteProduct(models.Model):
f
=
[
"id"
]
f
=
[
"id"
]
c
=
[[
'product_tmpl_id'
,
'='
,
product_tmpl_id
],
[
'name'
,
'='
,
partner_id
],
[
'date_end'
,
'='
,
False
]]
c
=
[[
'product_tmpl_id'
,
'='
,
product_tmpl_id
],
[
'name'
,
'='
,
partner_id
],
[
'date_end'
,
'='
,
False
]]
res_supplierinfo
=
api
.
search_read
(
'product.supplierinfo'
,
c
,
f
)
res_supplierinfo
=
api
.
search_read
(
'product.supplierinfo'
,
c
,
f
)
psi_id
=
res_supplierinfo
[
0
][
'id'
]
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
# End all active associations in case multiple are open (which shouldn't happen)
for
psi
in
res_supplierinfo
:
psi_id
=
psi
[
'id'
]
f
=
{
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
'date_end'
:
today
}
try
:
f
=
{
res
[
"update"
]
=
api
.
update
(
'product.supplierinfo'
,
psi_id
,
f
)
'date_end'
:
today
except
Exception
as
e
:
}
res
[
'error'
]
=
str
(
e
)
try
:
res
[
"update"
]
=
api
.
update
(
'product.supplierinfo'
,
psi_id
,
f
)
except
Exception
as
e
:
res
[
'error'
]
=
str
(
e
)
return
res
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