Commit e7fe0313 authored by Romain Courteaud's avatar Romain Courteaud 🐸

Even if delivered, we should always calculate consequences (like in

DeliveryRule).
Simulation state which can expand simulation must be defined in workflows, not
in rule.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3718 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7e99df49
...@@ -61,7 +61,7 @@ class InvoiceRule(DeliveryRule): ...@@ -61,7 +61,7 @@ class InvoiceRule(DeliveryRule):
# Simulation workflow # Simulation workflow
security.declareProtected(Permissions.ModifyPortalContent, 'expand') security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule, force=0, **kw): def expand(self, applied_rule, **kw):
""" """
Expands the current movement downward. Expands the current movement downward.
...@@ -76,72 +76,60 @@ class InvoiceRule(DeliveryRule): ...@@ -76,72 +76,60 @@ class InvoiceRule(DeliveryRule):
# Only expand if my_invoice is not None and # Only expand if my_invoice is not None and
# state is not 'confirmed' # state is not 'confirmed'
if my_invoice is not None: if my_invoice is not None:
# Only expand invoice rule if invoice not yet confirmed # First, check each contained movement and make
# (This is consistent with the fact that once simulation is # a list of invoice_line ids which do not need to be copied
# launched, we stick to it) # eventually delete movement which do not exist anylonger
if force or \ existing_uid_list = []
(applied_rule.getLastExpandSimulationState() not in \ movement_type_list = applied_rule.getPortalMovementTypeList()
self.getPortalReservedInventoryStateList() and \ # non generic
applied_rule.getLastExpandSimulationState() not in \ invoice_movement_type_list = \
self.getPortalCurrentInventoryStateList()): applied_rule.getPortalInvoiceMovementTypeList()
# First, check each contained movement and make for movement in applied_rule.contentValues(
# a list of invoice_line ids which do not need to be copied filter={'portal_type':movement_type_list}):
# eventually delete movement which do not exist anylonger invoice_element = movement.getDeliveryValue(
existing_uid_list = [] portal_type=invoice_movement_type_list)
movement_type_list = applied_rule.getPortalMovementTypeList()
# non generic
invoice_movement_type_list = \
applied_rule.getPortalInvoiceMovementTypeList()
for movement in applied_rule.contentValues(
filter={'portal_type':movement_type_list}):
invoice_element = movement.getDeliveryValue(
portal_type=invoice_movement_type_list)
if (invoice_element is None) or\ if (invoice_element is None) or\
(invoice_element.hasCellContent()) or\ (invoice_element.hasCellContent()) or\
(len(invoice_element.getDeliveryRelatedValueList()) > 1): (len(invoice_element.getDeliveryRelatedValueList()) > 1):
# Our invoice_element is already related # Our invoice_element is already related
# to another simulation movement # to another simulation movement
# Delete ourselve # Delete ourselve
# movement.flushActivity(invoke=0) # movement.flushActivity(invoke=0)
# XXX Make sure this is not deleted if already in delivery # XXX Make sure this is not deleted if already in delivery
applied_rule._delObject(movement.getId()) applied_rule._delObject(movement.getId())
else: else:
existing_uid_list_append(invoice_element.getUid()) existing_uid_list_append(invoice_element.getUid())
# Copy each movement (line or cell) from the invoice # Copy each movement (line or cell) from the invoice
# non generic # non generic
for invoice_line_object in my_delivery.getMovementList( for invoice_line_object in my_delivery.getMovementList(
portal_type=self.getPortalInvoiceMovementTypeList()): portal_type=self.getPortalInvoiceMovementTypeList()):
try: try:
# Only create if orphaned movement # Only create if orphaned movement
if invoice_line_object.getUid() not in existing_uid_list: if invoice_line_object.getUid() not in existing_uid_list:
# Generate a nicer ID # Generate a nicer ID
if invoice_line_object.getParentUid() ==\ if invoice_line_object.getParentUid() ==\
invoice_line_object.getExplanationUid(): invoice_line_object.getExplanationUid():
# We are on a line # We are on a line
new_id = invoice_line_object.getId() new_id = invoice_line_object.getId()
else: else:
# On a cell # On a cell
new_id = "%s_%s" % (invoice_line_object.getParentId(), new_id = "%s_%s" % (invoice_line_object.getParentId(),
invoice_line_object.getId()) invoice_line_object.getId())
# Generate the simulation movement # Generate the simulation movement
new_sim_mvt = applied_rule.newContent( new_sim_mvt = applied_rule.newContent(
portal_type=invoice_line_type, portal_type=invoice_line_type,
id=new_id, id=new_id,
order_value=invoice_line_object, order_value=invoice_line_object,
delivery_value=invoice_line_object, delivery_value=invoice_line_object,
# XXX Do we need to copy the quantity # XXX Do we need to copy the quantity
# Why not the resource, the variation,... # Why not the resource, the variation,...
quantity=invoice_line_object.getQuantity(), quantity=invoice_line_object.getQuantity(),
delivery_ratio=1, delivery_ratio=1,
deliverable=1) deliverable=1)
except AttributeError: except AttributeError:
LOG('ERP5: WARNING', 0, LOG('ERP5: WARNING', 0,
'AttributeError during expand on invoice line %s' \ 'AttributeError during expand on invoice line %s' \
% invoice_line_object.absolute_url()) % invoice_line_object.absolute_url())
# Now we can set the last expand simulation state to the
# current state
applied_rule.setLastExpandSimulationState(
my_invoice.getSimulationState())
# Pass to base class # Pass to base class
Rule.expand(self, applied_rule, force=force, **kw) Rule.expand(self, applied_rule, **kw)
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