Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Arnaud Fontaine
erp5
Commits
aa4d7994
Commit
aa4d7994
authored
Mar 15, 2018
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder: Supply builder work with period
parent
346aed80
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
31 deletions
+73
-31
product/ERP5/mixin/builder.py
product/ERP5/mixin/builder.py
+73
-31
No files found.
product/ERP5/mixin/builder.py
View file @
aa4d7994
...
@@ -391,48 +391,83 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -391,48 +391,83 @@ class BuilderMixin(XMLObject, Amount, Predicate):
)
)
return
movement
return
movement
now
=
DateTime
()
movement_list
=
[]
movement_list
=
[]
ordered_inventory
=
0
order_movement_list
=
[]
# Prepare history list to work with
# XXX This is dangerous if increase and decrease movements happen at
# the same date,
# In order to work at a due date, increase movement must be placed
# before decrease movement happening at the same date
history_list
=
resource_value
.
Resource_getInventoryHistoryList
(
history_list
=
resource_value
.
Resource_getInventoryHistoryList
(
from_date
=
from_date
,
from_date
=
from_date
,
node_uid
=
supply
.
getDestinationUid
()
node_uid
=
supply
.
getDestinationUid
()
# XXX This should be bound to a stard and stop date
# XXX This should be bound to a stard and stop date
)
)
while
history_list
:
date
,
inventory
,
quantity
=
history_list
[
0
]
# evaluate future inventory at date
future_inventory_to_date
=
portal
.
portal_simulation
.
getFutureInventory
(
to_date
=
from_date
,
resource_uid
=
resource_value
.
getUid
(),
node_uid
=
supply
.
getDestinationUid
(),
)
# Prepare period_list
limit_date
=
getPreviousValidDate
(
from_date
)
limit_date_list
=
[]
last_date
=
getPreviousValidDate
(
history_list
[
-
1
][
0
])
while
limit_date
<=
last_date
:
limit_date_list
.
append
(
limit_date
)
limit_date
=
DateTime
(
supply
.
getNextPeriodicalDate
(
limit_date
,
# Hackish and dangerous
next_start_date
=
limit_date
)).
earliestTime
()
# Create a movement per period
for
period_start_date
in
limit_date_list
:
# Prepare history list of the current period
next_period_start_date
=
DateTime
(
supply
.
getNextPeriodicalDate
(
period_start_date
,
next_start_date
=
period_start_date
)).
earliestTime
()
period_history_list
=
[]
while
history_list
and
history_list
[
0
][
0
]
<
next_period_start_date
:
period_history_list
.
append
(
history_list
.
pop
(
0
))
# Using period history list calculate min stock
min_inventory
=
self
.
Base_evaluateMinInventoryForSupplyAtDate
(
min_inventory
=
self
.
Base_evaluateMinInventoryForSupplyAtDate
(
supply
=
supply
,
supply
=
supply
,
history_list
=
history_list
,
history_list
=
period_
history_list
,
at_date
=
date
,
at_date
=
period_start_
date
,
conversion_ratio
=
default_quantity_unit_order_quantity_unit_conversion_ratio
,
conversion_ratio
=
default_quantity_unit_order_quantity_unit_conversion_ratio
,
)
)
quantity
=
0
#self.log("at %s min: %s, Ordered: %s, inventory:%s, quantity:%s" % (date, min_inventory, ordered_inventory, inventory, quantity))
#self.log("at %s min: %s, Ordered: %s, inventory:%s, quantity:%s" % (date, min_inventory, ordered_inventory, inventory, quantity))
if
ordered_inventory
+
(
inventory
-
quantity
)
<
min_inventory
:
# SKU
#import pdb;pdb.set_trace()
if
future_inventory_to_date
<
min_inventory
:
# SKU
quantity
=
min_inventory
-
(
inventory
-
quantity
)
-
ordered_inventory
quantity
=
min_inventory
-
future_inventory_to_date
ordered_quantity
,
ordered_unit
,
effective_date
,
start_date
,
delivery_date
,
quantity
=
minimalQuantity
(
quantity
,
date
)
# XXX CLN This is very naive, it has to be optimized
ordered_quantity
,
ordered_unit
,
effective_date
,
start_date
,
delivery_date
,
quantity
=
minimalQuantity
(
quantity
,
period_start_date
)
if
start_date
<=
supply
.
getStartDateRangeMax
()
\
# XXX CLN This is very naive, it has to be optimized
and
start_date
>=
supply
.
getStartDateRangeMin
():
if
start_date
>
supply
.
getStartDateRangeMax
():
self
.
log
(
"Week %s Will order %s at %s"
%
(
delivery_date
.
week
(),
quantity
,
delivery_date
))
break
ordered_inventory
=
ordered_inventory
+
quantity
if
start_date
<
supply
.
getStartDateRangeMin
():
movement_list
.
append
(
break
newMovement
(
effective_date
,
#self.log("Week %s Will order %s at %s for period %s" % (delivery_date.week(), quantity, delivery_date, period_start_date))
start_date
,
movement_list
.
append
(
delivery_date
,
newMovement
(
ordered_quantity
,
effective_date
,
ordered_unit
start_date
,
)
delivery_date
,
)
ordered_quantity
,
history_list
.
pop
(
0
)
ordered_unit
return
[]
)
)
# calculate inventory at the end of the period
future_inventory_to_date
+=
quantity
for
date
,
total_inventory
,
quantity
,
portal_type
in
period_history_list
:
future_inventory_to_date
+=
quantity
#return []
return
movement_list
return
movement_list
def
_searchMovementList
(
self
,
**
kw
):
def
_searchMovementList
(
self
,
**
kw
):
...
@@ -646,6 +681,13 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -646,6 +681,13 @@ class BuilderMixin(XMLObject, Amount, Predicate):
raise
SelectMethodError
(
'No updatable delivery found with %s for %s'
\
raise
SelectMethodError
(
'No updatable delivery found with %s for %s'
\
%
(
self
.
getPath
(),
movement_group_node_list
))
%
(
self
.
getPath
(),
movement_group_node_list
))
# if total quantity is 0 no need to create anything
total_quantity
=
0
for
movement
in
movement_group_node
.
getMovementList
():
total_quantity
+=
movement
.
getQuantity
()
if
total_quantity
==
0
:
return
delivery_list
delivery
=
self
.
_createDelivery
(
delivery_module
,
delivery
=
self
.
_createDelivery
(
delivery_module
,
movement_group_node
.
getMovementList
(),
movement_group_node
.
getMovementList
(),
activate_kw
)
activate_kw
)
...
...
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