Commit a5dafe43 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_base&erp5_property_sheets: add forward week field to define how many...

erp5_base&erp5_property_sheets: add forward week field to define how many weeks's stock we need to check
parent be05a394
...@@ -569,21 +569,36 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -569,21 +569,36 @@ class BuilderMixin(XMLObject, Amount, Predicate):
if len(stock_definition_supply_list): if len(stock_definition_supply_list):
return stock_definition_supply_list[0] return stock_definition_supply_list[0]
return default_supply return default_supply
def selectNextPeriodStartDate(start_date, forward_week):
week_counter = 0
next_period_start_date = start_date
while week_counter < forward_week:
next_period_start_date = DateTime(supply.getNextPeriodicalDate(
next_period_start_date,
next_start_date=next_period_start_date)).earliestTime()
week_counter += 1
return next_period_start_date
# Create a movement per period # Create a movement per period
next_next_period_start_date = None next_next_period_start_date = None
# default is one week
default_forward_week = supply.getForwardWeek() or 1
for period_start_date in limit_date_list: for period_start_date in limit_date_list:
# Prepare history list of the current period # Prepare history list of the current period
next_period_start_date = DateTime(supply.getNextPeriodicalDate( next_period_start_date = selectNextPeriodStartDate(period_start_date, default_forward_week)
period_start_date,
next_start_date=period_start_date)).earliestTime()
selected_supply = chooseCorrectSupply(default_supply = supply, start_date_range_min = period_start_date, start_date_range_max = next_period_start_date) selected_supply = chooseCorrectSupply(default_supply = supply, start_date_range_min = period_start_date, start_date_range_max = next_period_start_date)
#we found a stock definition supply #we found a stock definition supply
if selected_supply != supply: if selected_supply != supply:
min_stock_value = getCorrectSupplyParameter(selected_supply, supply, 'getMinOrderQuantity') / getDefaultQuantityUnitFlowQuantityUnitConversionRatio(selected_supply, supply) min_stock_value = getCorrectSupplyParameter(selected_supply, supply, 'getMinOrderQuantity') / getDefaultQuantityUnitFlowQuantityUnitConversionRatio(selected_supply, supply)
factor = getCorrectSupplyParameter(selected_supply, supply, 'getMinFlow') factor = getCorrectSupplyParameter(selected_supply, supply, 'getMinFlow')
selected_forward_week = selected_supply.getForwardWeek() or 1
if selected_forward_week != default_forward_week:
next_period_start_date = selectNextPeriodStartDate(period_start_date, selected_forward_week)
else: else:
# Fallback to current supply values # Fallback to current supply values
selected_forward_week = default_forward_week
min_stock_value = supply.getMinOrderQuantity() / default_quantity_unit_flow_quantity_unit_conversion_ratio min_stock_value = supply.getMinOrderQuantity() / default_quantity_unit_flow_quantity_unit_conversion_ratio
factor = supply.getMinFlow() factor = supply.getMinFlow()
period_history_list = [] period_history_list = []
...@@ -620,6 +635,7 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -620,6 +635,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
at_date=next_period_start_date, at_date=next_period_start_date,
factor=factor, factor=factor,
min_stock_value=min_inventory_end_of_period, min_stock_value=min_inventory_end_of_period,
forward_week =selected_forward_week
) )
week_consumption = self.Base_evaluateMinInventoryForSupplyAtDate( week_consumption = self.Base_evaluateMinInventoryForSupplyAtDate(
...@@ -627,16 +643,15 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -627,16 +643,15 @@ class BuilderMixin(XMLObject, Amount, Predicate):
history_list=period_history_list, history_list=period_history_list,
at_date=period_start_date, at_date=period_start_date,
factor=1, factor=1,
forward_week=selected_forward_week
) )
min_inventory = min_inventory_end_of_period + week_consumption min_inventory = min_inventory_end_of_period + week_consumption
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
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
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)
# 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():
......
...@@ -6,12 +6,6 @@ ...@@ -6,12 +6,6 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>BuilderMixin</string> </value> <value> <string>BuilderMixin</string> </value>
...@@ -50,12 +44,11 @@ ...@@ -50,12 +44,11 @@
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <tuple>
<string>W:638, 0: Bad indentation. Found 9 spaces, expected 8 (bad-indentation)</string> <string>W:520, 35: Unused variable \'portal_type\' (unused-variable)</string>
<string>W:663, 18: Unused variable \'total_inventory\' (unused-variable)</string>
<string>W:421, 4: Unused variable \'original_min_stock_value\' (unused-variable)</string> <string>W:421, 4: Unused variable \'original_min_stock_value\' (unused-variable)</string>
<string>W:422, 4: Unused variable \'original_factor\' (unused-variable)</string> <string>W:422, 4: Unused variable \'original_factor\' (unused-variable)</string>
<string>W:520, 14: Unused variable \'inventory\' (unused-variable)</string> <string>W:520, 14: Unused variable \'inventory\' (unused-variable)</string>
<string>W:520, 35: Unused variable \'portal_type\' (unused-variable)</string>
<string>W:648, 18: Unused variable \'total_inventory\' (unused-variable)</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -66,28 +59,13 @@ ...@@ -66,28 +59,13 @@
<item> <item>
<key> <string>workflow_history</string> </key> <key> <string>workflow_history</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI="> <record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="PersistentMapping" module="Persistence.mapping"/> <global name="PersistentMapping" module="Persistence.mapping"/>
</pickle> </pickle>
...@@ -100,7 +78,7 @@ ...@@ -100,7 +78,7 @@
<item> <item>
<key> <string>component_validation_workflow</string> </key> <key> <string>component_validation_workflow</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
...@@ -109,7 +87,7 @@ ...@@ -109,7 +87,7 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Acquired Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>acquisition_accessor_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>acquisition_base_category</string> </key>
<value>
<tuple>
<string>parent</string>
</tuple>
</value>
</item>
<item>
<key> <string>acquisition_mask_value</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>acquisition_object_id</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>acquisition_portal_type</string> </key>
<value> <string>python: portal.getPortalAcquisitionMovementTypeList() + portal.getPortalDeliveryTypeList() + portal.getPortalOrderTypeList() + portal.getPortalInvoiceTypeList() + portal.getPortalSupplyTypeList() + portal.getPortalProjectTypeList() + portal.getPortalOpenOrderTypeList() + portal.getPortalSupplyPathTypeList()</string> </value>
</item>
<item>
<key> <string>alt_accessor_id</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/int</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_acquired_property_id</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>content_translation_acquired_property_id</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>forward_week_property</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Acquired Property</string> </value>
</item>
<item>
<key> <string>property_default</string> </key>
<value> <string>python: 1</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment