Commit 22199961 authored by Xiaowu Zhang's avatar Xiaowu Zhang

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

See merge request !8
parents be05a394 a5dafe43
......@@ -569,21 +569,36 @@ class BuilderMixin(XMLObject, Amount, Predicate):
if len(stock_definition_supply_list):
return stock_definition_supply_list[0]
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
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:
# Prepare history list of the current period
next_period_start_date = DateTime(supply.getNextPeriodicalDate(
period_start_date,
next_start_date=period_start_date)).earliestTime()
next_period_start_date = selectNextPeriodStartDate(period_start_date, default_forward_week)
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
if selected_supply != supply:
min_stock_value = getCorrectSupplyParameter(selected_supply, supply, 'getMinOrderQuantity') / getDefaultQuantityUnitFlowQuantityUnitConversionRatio(selected_supply, supply)
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:
# Fallback to current supply values
selected_forward_week = default_forward_week
min_stock_value = supply.getMinOrderQuantity() / default_quantity_unit_flow_quantity_unit_conversion_ratio
factor = supply.getMinFlow()
period_history_list = []
......@@ -620,6 +635,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
at_date=next_period_start_date,
factor=factor,
min_stock_value=min_inventory_end_of_period,
forward_week =selected_forward_week
)
week_consumption = self.Base_evaluateMinInventoryForSupplyAtDate(
......@@ -627,16 +643,15 @@ class BuilderMixin(XMLObject, Amount, Predicate):
history_list=period_history_list,
at_date=period_start_date,
factor=1,
forward_week=selected_forward_week
)
min_inventory = min_inventory_end_of_period + week_consumption
quantity = 0
# 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:
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)
# XXX CLN This is very naive, it has to be optimized
if start_date > supply.getStartDateRangeMax():
......
......@@ -6,12 +6,6 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>BuilderMixin</string> </value>
......@@ -50,12 +44,11 @@
<key> <string>text_content_warning_message</string> </key>
<value>
<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:422, 4: Unused variable \'original_factor\' (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>
</value>
</item>
......@@ -66,28 +59,13 @@
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<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>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
......@@ -100,7 +78,7 @@
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
......@@ -109,7 +87,7 @@
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</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