Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
erp5
Commits
dec83150
Commit
dec83150
authored
Sep 05, 2024
by
Xiaowu Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_base: show calculation steps
parent
40aeb240
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
11 deletions
+48
-11
bt5/erp5_base/MixinTemplateItem/portal_components/mixin.erp5.BuilderMixin.py
...TemplateItem/portal_components/mixin.erp5.BuilderMixin.py
+43
-6
bt5/erp5_base/MixinTemplateItem/portal_components/mixin.erp5.BuilderMixin.xml
...emplateItem/portal_components/mixin.erp5.BuilderMixin.xml
+5
-5
No files found.
bt5/erp5_base/MixinTemplateItem/portal_components/mixin.erp5.BuilderMixin.py
View file @
dec83150
...
@@ -338,6 +338,14 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -338,6 +338,14 @@ class BuilderMixin(XMLObject, Amount, Predicate):
from_date
=
None
,
from_date
=
None
,
group_by_node
=
1
,
allow_intermediate_negative_stock
=
True
,
group_by_node
=
1
,
allow_intermediate_negative_stock
=
True
,
**
kw
):
**
kw
):
calculation_steps
=
'Calculation for %s with resource %s
\
n
'
%
(
supply
.
getRelativeUrl
(),
supply
.
getResourceReference
())
resource_dict
=
{
'reference'
:
supply
.
getResourceReference
(),
'date_list'
:
[],
'quantity_list'
:
[],
'url_list'
:
[],
'portal_type_list'
:
[]
}
portal
=
self
.
getPortalObject
()
portal
=
self
.
getPortalObject
()
if
from_date
is
None
:
if
from_date
is
None
:
from_date
=
DateTime
().
earliestTime
()
from_date
=
DateTime
().
earliestTime
()
...
@@ -519,13 +527,14 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -519,13 +527,14 @@ class BuilderMixin(XMLObject, Amount, Predicate):
# We only consider resources that have consumption movements in
# We only consider resources that have consumption movements in
# the future, for those who don't we do not build anything.
# the future, for those who don't we do not build anything.
has_consumption_movement
=
False
has_consumption_movement
=
False
for
date
,
inventory
,
quantity
,
portal_type
in
history_list
:
for
date
,
inventory
,
quantity
,
portal_type
,
_
in
history_list
:
if
quantity
<
0
:
if
quantity
<
0
:
has_consumption_movement
=
True
has_consumption_movement
=
True
break
break
if
not
has_consumption_movement
:
if
not
has_consumption_movement
:
return
[]
calculation_steps
=
calculation_steps
+
'Has no comsumption part in the future, Skip
\
n
'
return
[],
{
'calculation_step'
:
calculation_steps
,
'calculation_resource'
:
resource_dict
}
from_date
=
date
from_date
=
date
# Prepare period_list
# Prepare period_list
...
@@ -547,6 +556,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -547,6 +556,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
node_uid
=
supply
.
getParentValue
().
getDestinationDecisionUidList
(),
node_uid
=
supply
.
getParentValue
().
getDestinationDecisionUidList
(),
)
)
calculation_steps
=
calculation_steps
+
'Begin with status: Future inventory %s at date %s
\
n
'
%
(
future_inventory_to_date
,
limit_date_list
[
0
])
# We update history_list to include movements from the initial inventory date
# We update history_list to include movements from the initial inventory date
history_list
=
resource_value
.
Resource_getInventoryHistoryList
(
history_list
=
resource_value
.
Resource_getInventoryHistoryList
(
from_date
=
limit_date_list
[
0
],
from_date
=
limit_date_list
[
0
],
...
@@ -587,6 +598,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -587,6 +598,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
# default is one week
# default is one week
default_forward_week
=
supply
.
getForwardWeek
()
or
1
default_forward_week
=
supply
.
getForwardWeek
()
or
1
for
period_start_date
in
limit_date_list
:
for
period_start_date
in
limit_date_list
:
calculation_steps
=
calculation_steps
+
'
\
n
\
n
Calculate For Date: %s
\
n
'
%
period_start_date
# Prepare history list of the current period
# Prepare history list of the current period
next_period_start_date
=
selectNextPeriodStartDate
(
period_start_date
,
default_forward_week
)
next_period_start_date
=
selectNextPeriodStartDate
(
period_start_date
,
default_forward_week
)
...
@@ -647,14 +659,30 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -647,14 +659,30 @@ class BuilderMixin(XMLObject, Amount, Predicate):
factor
=
1
,
factor
=
1
,
forward_week
=
selected_forward_week
forward_week
=
selected_forward_week
)
)
calculation_steps
=
calculation_steps
+
'Check With:
\
n
'
for
period_history
in
period_history_list
:
resource_dict
[
'date_list'
].
append
(
'%s'
%
period_history
[
0
])
resource_dict
[
'quantity_list'
].
append
(
period_history
[
2
])
resource_dict
[
'url_list'
].
append
(
period_history
[
4
])
resource_dict
[
'portal_type_list'
].
append
(
period_history
[
3
])
calculation_steps
=
calculation_steps
+
'Date:%s quantity: %s portal_type: %s url: %s
\
n
'
%
(
period_history
[
0
],
period_history
[
2
],
period_history
[
3
],
period_history
[
4
])
calculation_steps
=
calculation_steps
+
'We have week consumption: %s
\
n
'
%
week_consumption
calculation_steps
=
calculation_steps
+
'We have Min Stock: %s
\
n
'
%
min_inventory_end_of_period
min_inventory
=
min_inventory_end_of_period
+
week_consumption
min_inventory
=
min_inventory_end_of_period
+
week_consumption
calculation_steps
=
calculation_steps
+
'We need stock: %s
\
n
'
%
min_inventory
quantity
=
0
quantity
=
0
# Only need to order if there are cosumption next week or if the min stock ratio is enabled
# Only need to order if there are cosumption next week or if the min stock ratio is enabled
calculation_steps
=
calculation_steps
+
'Inventory State: %s
\
n
'
%
future_inventory_to_date
if
(
week_consumption
!=
0
or
factor
)
and
future_inventory_to_date
<
min_inventory
:
if
(
week_consumption
!=
0
or
factor
)
and
future_inventory_to_date
<
min_inventory
:
quantity
=
min_inventory
-
future_inventory_to_date
quantity
=
min_inventory
-
future_inventory_to_date
calculation_steps
=
calculation_steps
+
'Need to order: %s
\
n
'
%
quantity
ordered_quantity
,
ordered_unit
,
effective_date
,
start_date
,
delivery_date
,
quantity
=
minimalQuantity
(
selected_supply
,
supply
,
quantity
,
period_start_date
)
ordered_quantity
,
ordered_unit
,
effective_date
,
start_date
,
delivery_date
,
quantity
=
minimalQuantity
(
selected_supply
,
supply
,
quantity
,
period_start_date
)
calculation_steps
=
calculation_steps
+
'Need to order: %s at %s after adjustment
\
n
'
%
(
quantity
,
start_date
)
# XXX CLN This is very naive, it has to be optimized
# XXX CLN This is very naive, it has to be optimized
if
start_date
>
supply
.
getStartDateRangeMax
():
if
start_date
>
supply
.
getStartDateRangeMax
():
break
break
...
@@ -662,13 +690,17 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -662,13 +690,17 @@ class BuilderMixin(XMLObject, Amount, Predicate):
# As we are going to need to go further in time to check if new Movements are needed
# As we are going to need to go further in time to check if new Movements are needed
# we need to keep inventory correct
# we need to keep inventory correct
#future_inventory_to_date += quantity
#future_inventory_to_date += quantity
for
date
,
total_inventory
,
quantity
,
portal_type
in
period_history_list
:
calculation_steps
=
calculation_steps
+
'Order date: %s < first_shipment_date: %s
\
n
'
%
(
start_date
,
first_shipment_date
)
calculation_steps
=
calculation_steps
+
'Accumulate stock until end of the period
\
n
'
for
date
,
total_inventory
,
quantity
,
portal_type
,
url
in
period_history_list
:
calculation_steps
=
calculation_steps
+
'At Date: %s Future Inventory: %s + quantity: %s of %s
\
n
'
%
(
date
,
future_inventory_to_date
,
quantity
,
url
)
future_inventory_to_date
+=
quantity
future_inventory_to_date
+=
quantity
continue
continue
#self.log("at %s min: %s, inventory:%s, quantity:%s" % (period_start_date, min_inventory, future_inventory_to_date, quantity))
#self.log("at %s min: %s, inventory:%s, quantity:%s" % (period_start_date, min_inventory, future_inventory_to_date, quantity))
if
quantity
!=
0
:
if
quantity
!=
0
:
self
.
log
(
"Week %s Will order %r at %s for period %s"
%
(
delivery_date
.
week
(),
quantity
,
delivery_date
,
period_start_date
)
)
calculation_steps
=
calculation_steps
+
"Week %s Will order %r at %s for period %s
\
n
"
%
(
delivery_date
.
week
(),
quantity
,
effective_date
,
period_start_date
)
movement_list
.
append
(
movement_list
.
append
(
newMovement
(
newMovement
(
effective_date
,
effective_date
,
...
@@ -680,12 +712,17 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -680,12 +712,17 @@ class BuilderMixin(XMLObject, Amount, Predicate):
)
)
# calculate inventory at the end of the period
# calculate inventory at the end of the period
calculation_steps
=
calculation_steps
+
'Accumulate stock until end of the period
\
n
'
calculation_steps
=
calculation_steps
+
'Future Inventory: %s + order quantity: %s
\
n
'
%
(
future_inventory_to_date
,
quantity
)
future_inventory_to_date
+=
quantity
future_inventory_to_date
+=
quantity
for
date
,
total_inventory
,
quantity
,
portal_type
in
period_history_list
:
for
date
,
total_inventory
,
quantity
,
portal_type
,
url
in
period_history_list
:
calculation_steps
=
calculation_steps
+
'At Date: %s Future Inventory: %s + quantity: %s of %s
\
n
'
%
(
date
,
future_inventory_to_date
,
quantity
,
url
)
future_inventory_to_date
+=
quantity
future_inventory_to_date
+=
quantity
#return []
#return []
return
movement_list
return
movement_list
,
{
'calculation_step'
:
calculation_steps
,
'calculation_resource'
:
resource_dict
}
def
_searchMovementList
(
self
,
**
kw
):
def
_searchMovementList
(
self
,
**
kw
):
"""
"""
...
...
bt5/erp5_base/MixinTemplateItem/portal_components/mixin.erp5.BuilderMixin.xml
View file @
dec83150
...
@@ -44,11 +44,11 @@
...
@@ -44,11 +44,11 @@
<key>
<string>
text_content_warning_message
</string>
</key>
<key>
<string>
text_content_warning_message
</string>
</key>
<value>
<value>
<tuple>
<tuple>
<string>
W:5
22
, 35: Unused variable \'portal_type\' (unused-variable)
</string>
<string>
W:5
30
, 35: Unused variable \'portal_type\' (unused-variable)
</string>
<string>
W:6
65
, 18: Unused variable \'total_inventory\' (unused-variable)
</string>
<string>
W:6
96
, 18: Unused variable \'total_inventory\' (unused-variable)
</string>
<string>
W:42
1
, 4: Unused variable \'original_min_stock_value\' (unused-variable)
</string>
<string>
W:42
9
, 4: Unused variable \'original_min_stock_value\' (unused-variable)
</string>
<string>
W:4
22
, 4: Unused variable \'original_factor\' (unused-variable)
</string>
<string>
W:4
30
, 4: Unused variable \'original_factor\' (unused-variable)
</string>
<string>
W:5
22
, 14: Unused variable \'inventory\' (unused-variable)
</string>
<string>
W:5
30
, 14: Unused variable \'inventory\' (unused-variable)
</string>
</tuple>
</tuple>
</value>
</value>
</item>
</item>
...
...
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