Commit e1d6b846 authored by Jean-Paul Smets's avatar Jean-Paul Smets

conflict solved


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@431 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a62aa2e4
...@@ -191,7 +191,7 @@ An ERP5 Rule...""" ...@@ -191,7 +191,7 @@ An ERP5 Rule..."""
production_section = my_context_movement.getSourceSection() production_section = my_context_movement.getSourceSection()
# Generate production and consumption lines # Generate production and consumption lines
my_quantity = my_context_movement.getTargetQuantity() my_quantity = my_context_movement.getTargetQuantity()
# LOG('Transformation', 0, str(my_transformation)) #LOG('Transformation', 0, str(my_transformation))
# We used to call this with context = my_context_movement # We used to call this with context = my_context_movement
# but it still has some issue which need to be fixed XXX As # but it still has some issue which need to be fixed XXX As
# a temp solution, we use the dict based API, but it is not general enough # a temp solution, we use the dict based API, but it is not general enough
...@@ -330,4 +330,4 @@ An ERP5 Rule...""" ...@@ -330,4 +330,4 @@ An ERP5 Rule..."""
def getSolverList(self, applied_rule): def getSolverList(self, applied_rule):
""" """
Returns a list Divergence solvers Returns a list Divergence solvers
""" """
\ No newline at end of file
...@@ -32,7 +32,7 @@ from AccessControl import ClassSecurityInfo ...@@ -32,7 +32,7 @@ from AccessControl import ClassSecurityInfo
from Globals import InitializeClass, DTMLFile from Globals import InitializeClass, DTMLFile
from Products.ERP5Type.Document.Folder import Folder from Products.ERP5Type.Document.Folder import Folder
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5.ERP5Globals import default_section_category, order_type_list, current_inventory_state_list from Products.ERP5.ERP5Globals import default_section_category, order_type_list, delivery_type_list, current_inventory_state_list
from Products.ERP5 import _dtmldir from Products.ERP5 import _dtmldir
...@@ -255,8 +255,18 @@ class SimulationTool (Folder, UniqueObject): ...@@ -255,8 +255,18 @@ class SimulationTool (Folder, UniqueObject):
self.group_list.append(PathGroup(movement)) self.group_list.append(PathGroup(movement))
def test(self,movement): def test(self,movement):
order_value = movement.getRootAppliedRule().getCausalityValue( if hasattr(movement, 'getRootAppliedRule'):
portal_type=order_type_list) order_value = movement.getRootAppliedRule().getCausalityValue(
portal_type=order_type_list)
if order_value is None:
# In some cases (ex. DeliveryRule), there is no order
# we may consider a PackingList as the order in the OrderGroup
order_value = movement.getRootAppliedRule().getCausalityValue(
portal_type=delivery_type_list)
else:
# This is a temp movement
order_value = None
if order_value is None: if order_value is None:
order_relative_url = None order_relative_url = None
else: else:
...@@ -656,10 +666,10 @@ class SimulationTool (Folder, UniqueObject): ...@@ -656,10 +666,10 @@ class SimulationTool (Folder, UniqueObject):
else : else :
average_price = 0 average_price = 0
#LOG('object mis ?jour',0,str(object_to_update.getRelativeUrl())) #LOG('object mis ?jour',0,str(object_to_update.getRelativeUrl()))
object_to_update.edit(target_quantity = cell_target_quantity, object_to_update._edit(target_quantity = cell_target_quantity,
quantity = cell_target_quantity, quantity = cell_target_quantity,
price = average_price, price = average_price,
force_update = 1 force_update = 1,
) )
# If we reach this point, it means we could # If we reach this point, it means we could
...@@ -906,153 +916,155 @@ class SimulationTool (Folder, UniqueObject): ...@@ -906,153 +916,155 @@ class SimulationTool (Folder, UniqueObject):
current_asset_price = 0.0 # Missing: initial inventory price !!! current_asset_price = 0.0 # Missing: initial inventory price !!!
current_inventory = 0.0 current_inventory = 0.0
# Parse each movement # Parse each movement
for b in self.Resource_zGetMovementHistoryList(resource=[resource], brain_list = self.Resource_zGetMovementHistoryList(resource=[resource],
variation_text=variation_text, variation_text=variation_text,
section_category=section_category, section_category=section_category,
node_category=node_category, node_category=node_category,
strict_membership=strict_membership, strict_membership=strict_membership,
simulation_state=simulation_state): # strict_membership not taken into account simulation_state=simulation_state) # strict_membership not taken into account
# We select movements related to certain nodes (ex. Stock) and sections (ex.Coramy Group)
result = []
for b in brain_list:
m = b.getObject() m = b.getObject()
result = []
update_source = 0
update_destination = 0
if m is not None: if m is not None:
previous_inventory = current_inventory previous_inventory = current_inventory
quantity = m.getQuantity() inventory_quantity = b.quantity # We should use the aggregated quantity provided by Resource_zGetMovementHistoryList
if quantity is None: quantity = m.getQuantity() # The movement quantity is important to determine the meaning of source and destination
quantity = 0.0 # Maybe we should take care of target qty in delired deliveries
if m.getSourceValue() is None: if quantity is None:
# This is a production movement quantity = 0.0
# Use Industrial Price if m.getSourceValue() is None:
current_inventory += quantity # Update inventory # This is a production movement or an inventory movement
asset_price = 0.0 # Use Industrial Price
# asset_price = m.getIndustrialPrice() current_inventory += inventory_quantity # Update inventory
result.append((m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(), if m.getPortalType() in ('Inventory Line', 'Inventory Cell'): # XX should be replaced by isInventory ???
m.getQuantity(), 'Production or Inventory', 'Price: %s' % asset_price asset_price = m.getPrice()
)) if asset_price in (0.0, None):
update_source = 0 asset_price = current_asset_price # Use current price if no price defined
update_destination = 1 else: # this is a production
elif m.getDestinationValue() is None: asset_price = m.getIndustrialPrice()
# This is a consumption movement - do nothing if asset_price is None: asset_price = current_asset_price # Use current price if no price defined
current_inventory += quantity # Update inventory result.append((m.getRelativeUrl(), m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getTargetQuantity(), 'Production or Inventory', 'Price: %s' % asset_price
))
elif m.getDestinationValue() is None:
# This is a consumption movement or an inventory movement
current_inventory += inventory_quantity # Update inventory
asset_price = current_asset_price
result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getTargetQuantity(), 'Consumption or Inventory', 'Price: %s' % asset_price
))
elif m.getSourceValue().isMemberOf(node_category) and m.getDestinationValue().isMemberOf(node_category):
# This is an internal movement
current_inventory += inventory_quantity # Update inventory
asset_price = current_asset_price
result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getTargetQuantity(), 'Internal', 'Price: %s' % asset_price
))
elif m.getSourceValue().isMemberOf(node_category) and quantity < 0:
# This is a physically inbound movement - try to use commercial price
if m.getSourceSectionValue() is None:
# No meaning
current_inventory += inventory_quantity # Update inventory
asset_price = current_asset_price asset_price = current_asset_price
result.append((m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(), result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getQuantity(), 'Consumption or Inventory', 'Price: %s' % asset_price m.getTargetQuantity(), 'Error', 'Price: %s' % asset_price
)) ))
update_source = 1 elif m.getDestinationSectionValue() is None:
update_destination = 0 # No meaning
elif m.getSourceValue().isMemberOf(node_category) and m.getDestinationValue().isMemberOf(node_category): current_inventory += inventory_quantity # Update inventory
# This is an internal movement - do nothing
current_inventory += quantity # Update inventory
asset_price = current_asset_price asset_price = current_asset_price
result.append((m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(), result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getQuantity(), 'Internal', 'Price: %s' % asset_price m.getTargetQuantity(), 'Error', 'Price: %s' % asset_price
)) ))
update_source = 1 elif m.getDestinationSectionValue().isMemberOf(section_category):
update_destination = 1 current_inventory += inventory_quantity # Update inventory
elif m.getSourceValue().isMemberOf(node_category) and quantity < 0: if m.getDestinationValue().isMemberOf('site/Piquage'):
# This is a physically inbound movement - try to use commercial price # Production
if m.getSourceSectionValue() is None: asset_price = m.getIndustrialPrice()
# No meaning if asset_price is None: asset_price = current_asset_price # Use current price if no price defined
current_inventory += quantity # Update inventory result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
asset_price = current_asset_price m.getTargetQuantity(), 'Production', 'Price: %s' % asset_price
result.append((m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(), ))
m.getQuantity(), 'Error', 'Price: %s' % asset_price
))
update_source = 1
update_destination = 1
elif m.getDestinationSectionValue() is None:
# No meaning
current_inventory += quantity # Update inventory
asset_price = current_asset_price
result.append((m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getQuantity(), 'Error', 'Price: %s' % asset_price
))
update_source = 1
update_destination = 1
elif m.getDestinationSectionValue().isMemberOf(section_category):
# Inbound from same section
current_inventory += quantity # Update inventory
asset_price = current_asset_price
result.append((m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getQuantity(), 'Inbound same section', 'Price: %s' % asset_price
))
update_source = 1
update_destination = 1
else: else:
current_inventory += quantity # Update inventory
asset_price = m.getPrice()
result.append((m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getQuantity(), 'Inbound different section', 'Price: %s' % asset_price
))
update_source = 1
update_destination = 0
elif m.getDestinationValue().isMemberOf(node_category) and quantity > 0:
# This is a physically inbound movement - try to use commercial price
# This is a physically inbound movement - try to use commercial price
if m.getSourceSectionValue() is None:
# No meaning
current_inventory += quantity # Update inventory
asset_price = current_asset_price
result.append((m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getQuantity(), 'Error', 'Price: %s' % asset_price
))
update_source = 1
update_destination = 1
elif m.getDestinationSectionValue() is None:
# No meaning
current_inventory += quantity # Update inventory
asset_price = current_asset_price
result.append((m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getQuantity(), 'Error', 'Price: %s' % asset_price
))
update_source = 1
update_destination = 1
elif m.getSourceSectionValue().isMemberOf(section_category):
# Inbound from same section # Inbound from same section
current_inventory += quantity # Update inventory
asset_price = current_asset_price asset_price = current_asset_price
result.append((m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(), result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getQuantity(), 'Inbound same section', 'Price: %s' % asset_price m.getTargetQuantity(), 'Inbound same section', 'Price: %s' % asset_price
)) ))
update_source = 1
update_destination = 1
else:
current_inventory += quantity # Update inventory
asset_price = m.getPrice()
result.append((m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getQuantity(), 'Inbound different section', 'Price: %s' % asset_price
))
update_source = 1
update_destination = 0
else: else:
# Outbound movement current_inventory += inventory_quantity # Update inventory
current_inventory += quantity # Update inventory asset_price = m.getPrice()
result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getTargetQuantity(), 'Inbound different section', 'Price: %s' % asset_price
))
elif m.getDestinationValue().isMemberOf(node_category) and quantity > 0:
# This is a physically inbound movement - try to use commercial price
if m.getSourceSectionValue() is None:
# No meaning
current_inventory += inventory_quantity # Update inventory
asset_price = current_asset_price
result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getTargetQuantity(), 'Error', 'Price: %s' % asset_price
))
elif m.getDestinationSectionValue() is None:
# No meaning
current_inventory += inventory_quantity # Update inventory
asset_price = current_asset_price asset_price = current_asset_price
result.append((m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(), result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getQuantity(), 'Outbound', 'Price: %s' % asset_price m.getTargetQuantity(), 'Error', 'Price: %s' % asset_price
)) ))
if quantity > 0: elif m.getSourceSectionValue().isMemberOf(section_category):
update_source = 0 current_inventory += inventory_quantity # Update inventory
update_destination = 1 if m.getSourceValue().isMemberOf('site/Piquage'):
# Production
asset_price = m.getIndustrialPrice()
if asset_price is None: asset_price = current_asset_price # Use current price if no price defined
result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getTargetQuantity(), 'Production', 'Price: %s' % asset_price
))
else: else:
update_source = 1 # Inbound from same section
update_destination = 0 asset_price = current_asset_price
result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
# Update asset_price m.getTargetQuantity(), 'Inbound same section', 'Price: %s' % asset_price
if current_inventory > 0: ))
# Update price with an average of incoming goods and current goods
current_asset_price = ( current_asset_price * previous_inventory + asset_price * quantity ) / float(current_inventory)
else: else:
# New price is the price of incoming goods - negative stock has no meaning for asset calculation current_inventory += inventory_quantity # Update inventory
current_asset_price = asset_price asset_price = m.getPrice()
result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
# Update Asset Price on the right side m.getTargetQuantity(), 'Inbound different section', 'Price: %s' % asset_price
if update_source: ))
m.setSourceAssetPrice(current_asset_price) else:
if update_destination: # Outbound movement
m.setDestinationAssetPrice(current_asset_price) current_inventory += inventory_quantity # Update inventory
asset_price = current_asset_price
return result result.append((m.getRelativeUrl(),m.getStartDate(), m.getSource(), m.getSourceSection(), m.getDestination(), m.getDestinationSection(),
m.getTargetQuantity(), 'Outbound', 'Price: %s' % asset_price
))
# Update asset_price
if current_inventory > 0:
if inventory_quantity is not None:
# Update price with an average of incoming goods and current goods
current_asset_price = ( current_asset_price * previous_inventory + asset_price * inventory_quantity ) / float(current_inventory)
else:
# New price is the price of incoming goods - negative stock has no meaning for asset calculation
current_asset_price = asset_price
result.append(('###New Asset Price', current_asset_price, 'New Inventory', current_inventory))
# Update Asset Price on the right side
if m.getSourceSectionValue() is not None and m.getSourceSectionValue().isMemberOf(section_category):
# for each movement, source section is member of one and one only accounting category
# therefore there is only one and one only source asset price
m._setSourceAssetPrice(current_asset_price)
if m.getDestinationSectionValue() is not None and m.getDestinationSectionValue().isMemberOf(section_category):
# for each movement, destination section is member of one and one only accounting category
# therefore there is only one and one only destination asset price
m._setDestinationAssetPrice(current_asset_price)
# Global reindexing required afterwards
return result
InitializeClass(SimulationTool) InitializeClass(SimulationTool)
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