Commit d6d633e4 authored by Jérome Perrin's avatar Jérome Perrin

bugfix in resource (currency) Lookup


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4010 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1fcdde4c
...@@ -87,16 +87,9 @@ class InvoiceTransactionRule(Rule, XMLMatrix): ...@@ -87,16 +87,9 @@ class InvoiceTransactionRule(Rule, XMLMatrix):
return 1 return 1
return 0 return 0
# 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):
""" """Expands the current movement downward.
Expands the current movement downward.
-> new status -> expanded
An applied rule can be expanded only if its parent movement
is expanded.
""" """
invoice_transaction_line_type = 'Simulation Movement' invoice_transaction_line_type = 'Simulation Movement'
...@@ -136,47 +129,52 @@ class InvoiceTransactionRule(Rule, XMLMatrix): ...@@ -136,47 +129,52 @@ class InvoiceTransactionRule(Rule, XMLMatrix):
, portal_type=invoice_transaction_line_type) , portal_type=invoice_transaction_line_type)
# get the resource (in that order): # get the resource (in that order):
# resource from the invoice (using deliveryValue) # * resource from the invoice (using deliveryValue)
# price_currency from the invoice # * price_currency from the invoice
# price_currency from the parents simulation movement's deliveryValue # * price_currency from the parents simulation movement's
# price_currency from the top level simulation movement's orderValue # deliveryValue
# * price_currency from the top level simulation movement's
# orderValue
resource = None resource = None
invoice_line = my_invoice_line_simulation.getDeliveryValue() invoice_line = my_invoice_line_simulation.getDeliveryValue()
if invoice_line is not None : if invoice_line is not None :
invoice = invoice_line.getExplanationValue() invoice = invoice_line.getExplanationValue()
if invoice.getResource() is not None : if hasattr(invoice, 'getResource') and \
invoice.getResource() is not None :
resource = invoice.getResource() resource = invoice.getResource()
elif hasattr(invoice, 'getPriceCurrency') and \ elif hasattr(invoice, 'getPriceCurrency') and \
invoice.getPriceCurrency() is not None : invoice.getPriceCurrency() is not None :
resource = invoice.getPriceCurrency() resource = invoice.getPriceCurrency()
else: if resource is None :
# search the resource on parents simulation movement's deliveries # search the resource on parents simulation movement's deliveries
simulation_movement = applied_rule.getParent() simulation_movement = applied_rule.getParent()
portal_simulation = self.getPortal().portal_simulation portal_simulation = self.getPortalObject().portal_simulation
while resource is None and simulation_movement != portal_simulation : while resource is None and \
delivery = simulation_movement.getDeliveryValue() simulation_movement != portal_simulation :
if hasattr(delivery, 'getPriceCurrency') and \ delivery = simulation_movement.getDeliveryValue()
delivery.getPriceCurrency() is not None : if hasattr(delivery, 'getPriceCurrency') and \
resource = delivery.getPriceCurrency() delivery.getPriceCurrency() is not None :
if simulation_movement.getParent().getParent() \ resource = delivery.getPriceCurrency()
== portal_simulation : if simulation_movement.getParent().getParent() \
# we are on the first simulation movement, == portal_simulation :
# we'll try to get the resource from it's order. # we are on the first simulation movement, we'll try
order = simulation_movement.getOrderValue() # to get the resource from it's order price currency.
if hasattr(order, 'getPriceCurrency') and \ order = simulation_movement.getOrderValue()
order.getPriceCurrency() is not None : if hasattr(order, 'getPriceCurrency') and \
resource = order.getPriceCurrency() order.getPriceCurrency() is not None :
simulation_movement = simulation_movement.getParent().getParent() resource = order.getPriceCurrency()
simulation_movement = simulation_movement\
.getParent().getParent()
if resource is None : if resource is None :
# last resort : get the resource from the rule # last resort : get the resource from the rule
resource = transaction_line.getResource() or my_cell.getResource() resource = transaction_line.getResource() or my_cell.getResource()
if resource in (None, '') : if resource in (None, '') :
# XXX this happen in many order, so this log is probably useless
LOG("InvoiceTransactionRule", PROBLEM, LOG("InvoiceTransactionRule", PROBLEM,
"Unable to expand %s: no resource"%applied_rule.getPath()) "expanding %s: without resource"%applied_rule.getPath())
raise ValueError, 'no resource for %s' % \ simulation_movement.edit(
transaction_line.getPath()
simulation_movement._edit(
source = transaction_line.getSource() source = transaction_line.getSource()
, destination = transaction_line.getDestination() , destination = transaction_line.getDestination()
, source_section = my_invoice_line_simulation.getSourceSection() , source_section = my_invoice_line_simulation.getSourceSection()
...@@ -247,23 +245,25 @@ class InvoiceTransactionRule(Rule, XMLMatrix): ...@@ -247,23 +245,25 @@ class InvoiceTransactionRule(Rule, XMLMatrix):
return 1 return 1
# Matrix related # Matrix related
security.declareProtected( Permissions.ModifyPortalContent, 'newCellContent' ) security.declareProtected( Permissions.ModifyPortalContent,
def newCellContent(self, id,**kw): 'newCellContent' )
""" def newCellContent(self, id, **kw):
This method can be overriden """Creates a new Cell.
This method can be overriden
""" """
self.invokeFactory(type_name='Accounting Rule Cell',id=id) self.invokeFactory(type_name='Accounting Rule Cell', id=id)
new_cell = self.get(id) new_cell = self.get(id)
return new_cell return new_cell
security.declareProtected(Permissions.ModifyPortalContent, 'updateMatrix') security.declareProtected(Permissions.ModifyPortalContent, 'updateMatrix')
def updateMatrix(self) : def updateMatrix(self) :
""" """This methods updates the matrix so that cells are consistent
This methods updates the matrix so that cells are consistent with the predicates. with the predicates.
""" """
base_id = 'movement' base_id = 'movement'
kwd = {'base_id': base_id} kwd = {'base_id': base_id}
new_range = self.InvoiceTransactionRule_asCellRange() # This is a site dependent script # This is a site dependent script
new_range = self.InvoiceTransactionRule_asCellRange()
self._setCellRange(*new_range, **kwd) self._setCellRange(*new_range, **kwd)
cell_range_key_list = self.getCellRangeKeyList(base_id = base_id) cell_range_key_list = self.getCellRangeKeyList(base_id = base_id)
......
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