Commit fd86b745 authored by Romain Courteaud's avatar Romain Courteaud

Use new TargetSolver API.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3146 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4802cf0c
############################################################################## ##############################################################################
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002, 2005 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com> # Jean-Paul Smets-Solanes <jp@nexedi.com>
# Romain Courteaud <romain@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential # programmers who take the whole responsability of assessing all potential
...@@ -26,10 +27,7 @@ ...@@ -26,10 +27,7 @@
# #
############################################################################## ##############################################################################
from Products.ERP5.Tool.SimulationTool import registerTargetSolver
from TargetSolver import TargetSolver from TargetSolver import TargetSolver
from zLOG import LOG from zLOG import LOG
class CopyToTarget(TargetSolver): class CopyToTarget(TargetSolver):
...@@ -38,21 +36,13 @@ class CopyToTarget(TargetSolver): ...@@ -38,21 +36,13 @@ class CopyToTarget(TargetSolver):
only acceptable for root movements. The meaning of only acceptable for root movements. The meaning of
this solver of other movements is far from certain. this solver of other movements is far from certain.
""" """
def solve(self, movement):
def solve(self, movement, new_target):
""" """
Adopt values as new target Adopt values as new target
""" """
# Reduce quantity # Reduce quantity
movement.setQuantity(new_target.target_quantity) movement.edit(
# Change dates quantity=movement.getDeliveryQuantity() * movement.getDeliveryRatio(),
movement.setStartDate(new_target.target_start_date) start_date=movement.getDeliveryStartDateList()[0],
movement.setStopDate(new_target.target_stop_date) stop_date=movement.getDeliveryStopDateList()[0]
)
def close(self):
"""
After resolution has taken place, create a new delivery
with deliverable split movements.
"""
registerTargetSolver(CopyToTarget)
############################################################################## ##############################################################################
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002, 2005 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com> # Jean-Paul Smets-Solanes <jp@nexedi.com>
# Romain Courteaud <romain@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential # programmers who take the whole responsability of assessing all potential
...@@ -26,8 +27,6 @@ ...@@ -26,8 +27,6 @@
# #
############################################################################## ##############################################################################
from Products.ERP5.Tool.SimulationTool import registerTargetSolver
from CopyToTarget import CopyToTarget from CopyToTarget import CopyToTarget
from zLOG import LOG from zLOG import LOG
...@@ -39,56 +38,38 @@ class SplitAndDefer(CopyToTarget): ...@@ -39,56 +38,38 @@ class SplitAndDefer(CopyToTarget):
may need to be delivered later. Solver accumulates such movements may need to be delivered later. Solver accumulates such movements
in the solving process and creates a new delivery in the solving process and creates a new delivery
This only works when some movements can not be delivered (excessive qty is not covered) This only works when some movements can not be delivered
(excessive qty is not covered)
""" """
def __init__(self, simulation_tool, **kw): def solve(self, movement):
"""
Creates an instance of TargetSolver with parameters
"""
CopyToTarget.__init__(self, simulation_tool, **kw)
self.split_movement_list = []
def solve(self, movement, new_target):
""" """
Split a movement and accumulate Split a movement and accumulate
""" """
target_quantity = movement.getTargetQuantity() movement_quantity = movement.getQuantity()
new_target_quantity = new_target.target_quantity delivery_quantity = movement.getDeliveryQuantity()
if target_quantity > new_target_quantity: new_movement_quantity = delivery_quantity * movement.getDeliveryRatio()
if movement_quantity > new_movement_quantity:
split_index = 0 split_index = 0
new_id = "%s_split_%s" % (movement.getId(), split_index) new_id = "%s_split_%s" % (movement.getId(), split_index)
while getattr(movement.aq_parent, new_id, None) is not None: while getattr(movement.aq_parent, new_id, None) is not None:
split_index += 1 split_index += 1
new_id = "%s_split_%s" % (movement.getId(), split_index) new_id = "%s_split_%s" % (movement.getId(), split_index)
# Adopt different dates for defferred movements # Adopt different dates for defferred movements
# XXX What about quantity_unit ? resource ? new_movement = movement.aq_parent.newContent(
new_movement = movement.aq_parent.newContent(portal_type = "Simulation Movement", portal_type="Simulation Movement",
id = new_id, id=new_id,
efficiency = movement.getEfficiency(), efficiency=movement.getEfficiency(),
target_efficiency = movement.getTargetEfficiency(), start_date=self.start_date,
target_start_date = self.target_start_date, stop_date=self.stop_date,
target_stop_date = self.target_stop_date, # XXX resource
start_date = self.target_start_date, order=movement.getOrder(),
stop_date = self.target_stop_date, deliverable=movement.isDeliverable(),
quantity=movement_quantity-new_movement_quantity,
source = movement.getSource(), source = movement.getSource(),
destination = movement.getDestination(), destination = movement.getDestination(),
source_section = movement.getSourceSection(), source_section = movement.getSourceSection(),
destination_section = movement.getDestinationSection(), destination_section = movement.getDestinationSection(),
order = movement.getOrder(),
deliverable = movement.isDeliverable()
) )
new_movement._setTargetQuantity(target_quantity - new_target_quantity) CopyToTarget.solve(self, movement)
new_movement._setQuantity(target_quantity - new_target_quantity)
self.split_movement_list.append(new_movement)
CopyToTarget.solve(self, movement, new_target)
def close(self):
"""
After resolution has taken place, create a new delivery
with deliverable split movements.
"""
movement_group = self.simulation_tool.collectMovement(self.split_movement_list)
return self.simulation_tool.buildDeliveryList(movement_group)
registerTargetSolver(SplitAndDefer)
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