Commit bc9f3d24 authored by Rafael Monnerat's avatar Rafael Monnerat

Remove old_expand method. It is not used and can generate mistakes.




git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10257 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e22553d4
...@@ -186,102 +186,6 @@ class InvoiceTransactionRule(Rule, PredicateMatrix): ...@@ -186,102 +186,6 @@ class InvoiceTransactionRule(Rule, PredicateMatrix):
# Pass to base class # Pass to base class
Rule.expand(self, applied_rule, force=force, **kw) Rule.expand(self, applied_rule, force=force, **kw)
#### old expand method kept for reference
def old_expand(self, applied_rule, force=0, **kw):
""" Expands the current movement downward.
"""
# First, get the simulation movement we were expanded from
my_invoice_line_simulation = applied_rule.getParentValue()
# Next, we can try to expand the rule
if force or \
(applied_rule.getLastExpandSimulationState()\
not in self.getPortalReservedInventoryStateList() and \
applied_rule.getLastExpandSimulationState()\
not in self.getPortalCurrentInventoryStateList()):
# Find a matching cell
my_cell = self._getMatchingCell(my_invoice_line_simulation)
if my_cell is not None :
my_cell_transaction_id_list = my_cell.contentIds()
else :
my_cell_transaction_id_list = []
if my_cell is not None : # else, we do nothing
# check each contained movement and delete
# those that we don't need
for movement in applied_rule.objectValues():
if movement.getId() not in my_cell_transaction_id_list :
applied_rule.deleteContent(movement.getId())
# Add every movement from the Matrix to the Simulation
for transaction_line in my_cell.objectValues() :
if transaction_line.getId() in applied_rule.objectIds() :
my_simulation_movement = applied_rule[transaction_line.getId()]
else :
my_simulation_movement = applied_rule.newContent(
id = transaction_line.getId()
, portal_type=self.movement_type)
# get the resource (in that order):
# * resource from the invoice (using deliveryValue)
# * price_currency from the invoice
# * price_currency from the parents simulation movement's
# deliveryValue
# * price_currency from the top level simulation movement's
# orderValue
resource = None
invoice_line = my_invoice_line_simulation.getDeliveryValue()
if invoice_line is not None :
invoice = invoice_line.getExplanationValue()
resource = invoice.getProperty('resource',
invoice.getProperty('price_currency', None))
if resource is None :
# search the resource on parents simulation movement's deliveries
simulation_movement = applied_rule.getParentValue()
portal_simulation = self.getPortalObject().portal_simulation
while resource is None and \
simulation_movement != portal_simulation :
delivery = simulation_movement.getDeliveryValue()
if delivery is not None:
resource = delivery.getProperty('price_currency', None)
if simulation_movement.getParentValue().getParentValue() \
== portal_simulation :
# we are on the first simulation movement, we'll try
# to get the resource from it's order price currency.
order = simulation_movement.getOrderValue()
resource = order.getProperty('price_currency', None)
simulation_movement = simulation_movement\
.getParentValue().getParentValue()
if resource is None :
# last resort : get the resource from the rule
resource = transaction_line.getResource() or my_cell.getResource()
if resource in (None, '') :
# XXX this happen in many order, so this log is probably useless
LOG("InvoiceTransactionRule", PROBLEM,
"expanding %s: without resource" % applied_rule.getPath())
quantity_precision = self.getQuantityPrecisionFromResource(resource)
my_simulation_movement._edit(
source = transaction_line.getSource()
, destination = transaction_line.getDestination()
, source_section = my_invoice_line_simulation.getSourceSection()
, destination_section = my_invoice_line_simulation\
.getDestinationSection()
, resource = resource
# calculate (quantity * price) * cell_quantity
, quantity = round((my_invoice_line_simulation.getQuantity()
* my_invoice_line_simulation.getPrice())
* transaction_line.getQuantity(), quantity_precision)
, start_date = my_invoice_line_simulation.getStartDate()
, stop_date = my_invoice_line_simulation.getStopDate()
, force_update = 1
)
# Pass to base class
Rule.expand(self, applied_rule, force=force, **kw)
# Matrix related # Matrix related
security.declareProtected( Permissions.ModifyPortalContent, security.declareProtected( Permissions.ModifyPortalContent,
......
...@@ -170,65 +170,4 @@ class InvoicingRule(Rule): ...@@ -170,65 +170,4 @@ class InvoicingRule(Rule):
def isDeliverable(self, movement): def isDeliverable(self, movement):
return movement.getResource() is not None return movement.getResource() is not None
#### old expand method kept for reference
def old_expand(self, applied_rule, **kw):
"""
Expands the current movement downward.
"""
delivery_line_type = 'Simulation Movement'
# Source that movement from the next node / stock
context_movement = applied_rule.getParentValue()
# Do not invoice within the same entity or whenever entities are
# not all defined
# It is OK to invoice within different entities of the same company
# if we wish to get some internal analytical accounting
# but that requires some processing to produce a balance sheet
source_section = context_movement.getSourceSection()
destination_section = context_movement.getDestinationSection()
if source_section == destination_section or source_section is None \
or destination_section is None:
return Rule.expand(self, applied_rule, **kw)
if context_movement.getSource() is not None:
# XXX Please explain why ? Let us consider for
# example a consumption movement of garbage which we
# want to be invoiced (the cleanup company is working
# within our premises)
#
# We should only expand movements if they have a source
# otherwise, it creates infinite recursion
# This happens for example whenever the source of a movement is
# acquired from an order which is deleted afterwards
new_id = 'inv_mvt'
if new_id in applied_rule.objectIds():
invoice_line = applied_rule[new_id]
else:
invoice_line = applied_rule.newContent(
type_name = delivery_line_type,
id = new_id
)
# Edit movement
invoice_line._edit(
price = context_movement.getPrice(),
quantity = context_movement.getQuantity(),
quantity_unit = context_movement.getQuantityUnit(),
efficiency = context_movement.getEfficiency(),
resource = context_movement.getResource(),
variation_category_list = context_movement.\
getVariationCategoryList(),
variation_property_dict = context_movement.\
getVariationPropertyDict(),
start_date = context_movement.getStartDate(),
stop_date = context_movement.getStopDate(),
source = context_movement.getSource(),
source_section = source_section,
destination = context_movement.getDestination(),
destination_section = destination_section,
# We do need to collect invoice lines to build invoices
deliverable = 1,
)
# Create one submovement which sources the transformation
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