Commit 7e99df49 authored by Romain Courteaud's avatar Romain Courteaud

Make InvoiceRule more generic: it is now a subclass of DeliveryRule.

Clean up expand method.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3717 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f6294440
############################################################################## ##############################################################################
# #
# 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
...@@ -29,14 +30,14 @@ ...@@ -29,14 +30,14 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5.Document.Rule import Rule from Products.ERP5.Document.Rule import Rule
from Products.ERP5.Document.DeliveryRule import DeliveryRule
from zLOG import LOG from zLOG import LOG
class InvoiceRule(Rule): class InvoiceRule(DeliveryRule):
""" """
Invoice Rule object make sure an Invoice in the simulation Invoice Rule object make sure an Invoice in the simulation
is consistent with the real invoice is consistent with the real invoice
WARNING: what to do with movement split ? WARNING: what to do with movement split ?
""" """
...@@ -58,14 +59,6 @@ class InvoiceRule(Rule): ...@@ -58,14 +59,6 @@ class InvoiceRule(Rule):
, PropertySheet.DublinCore , PropertySheet.DublinCore
) )
def test(self, movement):
"""
Tests if the rule (still) applies
"""
# An invoice rule never applies since it is always explicitely instanciated
# This will change in the near future : invoice will be generated following a delivery
return 0
# 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, force=0, **kw):
...@@ -78,123 +71,77 @@ class InvoiceRule(Rule): ...@@ -78,123 +71,77 @@ class InvoiceRule(Rule):
is expanded. is expanded.
""" """
invoice_line_type = 'Simulation Movement' invoice_line_type = 'Simulation Movement'
# Get the invoice where we come from # Get the invoice where we come from
my_invoice = applied_rule.getDefaultCausalityValue() my_invoice = applied_rule.getDefaultCausalityValue()
# 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 (This is consistent # Only expand invoice rule if invoice not yet confirmed
# with the fact that once simulation is launched, we stick to it) # (This is consistent with the fact that once simulation is
# launched, we stick to it)
if force or \ if force or \
(applied_rule.getLastExpandSimulationState() not in self.getPortalReservedInventoryStateList() and \ (applied_rule.getLastExpandSimulationState() not in \
applied_rule.getLastExpandSimulationState() not in self.getPortalCurrentInventoryStateList()): self.getPortalReservedInventoryStateList() and \
applied_rule.getLastExpandSimulationState() not in \
self.getPortalCurrentInventoryStateList()):
# First, check each contained movement and make # First, check each contained movement and make
# a list of invoice_line ids which do not need to be copied # a list of invoice_line ids which do not need to be copied
# eventually delete movement which do not exist anylonger # eventually delete movement which do not exist anylonger
existing_uid_list = [] existing_uid_list = []
for movement in applied_rule.contentValues(filter={'portal_type':self.getPortalMovementTypeList()}): movement_type_list = applied_rule.getPortalMovementTypeList()
invoice_element = movement.getDeliveryValue(portal_type=self.getPortalInvoiceMovementTypeList()) # non generic
if invoice_element is None: invoice_movement_type_list = \
# Does not exist any longer applied_rule.getPortalInvoiceMovementTypeList()
movement.flushActivity(invoke=0) for movement in applied_rule.contentValues(
applied_rule._delObject(movement.getId()) # XXXX Make sur this is not deleted if already in delivery filter={'portal_type':movement_type_list}):
else: invoice_element = movement.getDeliveryValue(
if getattr(invoice_element, 'isCell', 0): portal_type=invoice_movement_type_list)
# It is a Cell
existing_uid_list += [invoice_element.getUid()] if (invoice_element is None) or\
elif invoice_element.hasCellContent(): (invoice_element.hasCellContent()) or\
# Do not keep head of cells (len(invoice_element.getDeliveryRelatedValueList()) > 1):
invoice_element.flushActivity(invoke=0) # Our invoice_element is already related
applied_rule._delObject(movement.getId()) # XXXX Make sur this is not deleted if already in delivery # to another simulation movement
# Delete ourselve
# movement.flushActivity(invoke=0)
# XXX Make sure this is not deleted if already in delivery
applied_rule._delObject(movement.getId())
else: else:
# It is a Line existing_uid_list_append(invoice_element.getUid())
existing_uid_list += [invoice_element.getUid()]
# Copy each movement (line or cell) from the invoice # Copy each movement (line or cell) from the invoice
for invoice_line_object in my_invoice.contentValues(filter={'portal_type':self.getPortalInvoiceMovementTypeList()}): # non generic
for invoice_line_object in my_delivery.getMovementList(
portal_type=self.getPortalInvoiceMovementTypeList()):
try: try:
if invoice_line_object.hasCellContent(): # Only create if orphaned movement
for c in invoice_line_object.getCellValueList():
#LOG('Cell in', 0, '%s %s' % (c.getUid(), existing_uid_list))
if c.getUid() not in existing_uid_list:
new_id = invoice_line_object.getId() + '_' + c.getId()
#LOG('Create Cell', 0, str(new_id))
applied_rule.newContent(
portal_type = invoice_line_type
, delivery_value = c
, deliverable = 1
)
#LOG('After Create Cell', 0, str(new_id))
else:
if invoice_line_object.getUid() not in existing_uid_list: if invoice_line_object.getUid() not in existing_uid_list:
# Generate a nicer ID
if invoice_line_object.getParentUid() ==\
invoice_line_object.getExplanationUid():
# We are on a line
new_id = invoice_line_object.getId() new_id = invoice_line_object.getId()
#LOG('Create Line', 0, str(new_id)) else:
applied_rule.newContent( # On a cell
portal_type = invoice_line_type new_id = "%s_%s" % (invoice_line_object.getParentId(),
, delivery_value = invoice_line_object invoice_line_object.getId())
, deliverable = 1 # Generate the simulation movement
) new_sim_mvt = applied_rule.newContent(
#LOG('After Create Line', 0, str(new_id)) portal_type=invoice_line_type,
# Source, Destination, Quantity, Date, etc. are id=new_id,
# acquired from the invoice and need not to be copied. order_value=invoice_line_object,
delivery_value=invoice_line_object,
# XXX Do we need to copy the quantity
# Why not the resource, the variation,...
quantity=invoice_line_object.getQuantity(),
delivery_ratio=1,
deliverable=1)
except AttributeError: except AttributeError:
LOG('ERP5: WARNING', 0, 'AttributeError during expand on invoice line %s' LOG('ERP5: WARNING', 0,
'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
# Now we can set the last expand simulation state to the current state # current state
applied_rule.setLastExpandSimulationState(my_invoice.getSimulationState()) 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, force=force, **kw)
security.declareProtected(Permissions.ModifyPortalContent, 'solve')
def solve(self, applied_rule, solution_list):
"""
Solve inconsitency according to a certain number of solutions
templates. This updates the
-> new status -> solved
This applies a solution to an applied rule. Once
the solution is applied, the parent movement is checked.
If it does not diverge, the rule is reexpanded. If not,
diverge is called on the parent movement.
"""
security.declareProtected(Permissions.ModifyPortalContent, 'diverge')
def diverge(self, applied_rule):
"""
-> new status -> diverged
This basically sets the rule to "diverged"
and blocks expansion process
"""
# Solvers
security.declareProtected(Permissions.View, 'isDivergent')
def isDivergent(self, applied_rule):
"""
Returns 1 if divergent rule
"""
security.declareProtected(Permissions.View, 'getDivergenceList')
def getDivergenceList(self, applied_rule):
"""
Returns a list Divergence descriptors
"""
security.declareProtected(Permissions.View, 'getSolverList')
def getSolverList(self, applied_rule):
"""
Returns a list Divergence solvers
"""
# Deliverability / orderability
def isOrderable(self, m):
return 1
def isDeliverable(self, m):
if m.getSimulationState() in self.getPortalDraftOrderStateList() :
return 0
return 1
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