Commit 85b97ee1 authored by Jérome Perrin's avatar Jérome Perrin

* get the currency resource from the "Price Currency" of Invoice, Packing List or Order.

* restore the copying of id in rule it was accientally removed


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3743 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3f3363b0
...@@ -66,9 +66,8 @@ class InvoiceTransactionRule(Rule, XMLMatrix): ...@@ -66,9 +66,8 @@ class InvoiceTransactionRule(Rule, XMLMatrix):
Browse all cells and test them until match found Browse all cells and test them until match found
""" """
for cell in self.getCellValueList(base_id = 'movement'): for cell in self.getCellValueList(base_id = 'movement'):
LOG('?? Trying Cell', BLATHER, cell.getRelativeUrl())
if cell.test(movement): if cell.test(movement):
LOG('Found Cell', BLATHER, cell.getRelativeUrl()) # XXX level LOG('Found Cell', BLATHER, cell.getRelativeUrl())
return cell return cell
return None return None
...@@ -76,12 +75,14 @@ class InvoiceTransactionRule(Rule, XMLMatrix): ...@@ -76,12 +75,14 @@ class InvoiceTransactionRule(Rule, XMLMatrix):
""" """
Tests if the rule (still) applies Tests if the rule (still) applies
""" """
# An invoice transaction rule applies when the movement's parent is an invoice rule # An invoice transaction rule applies when the movement's
# parent is an invoice rule
parent = movement.getParentValue() parent = movement.getParentValue()
parent_rule_value = parent.getSpecialiseValue() parent_rule_value = parent.getSpecialiseValue()
if parent_rule_value is None: if parent_rule_value is None:
return 0 return 0
if parent_rule_value.getPortalType() in ('Invoicing Rule', 'Invoice Rule'): if parent_rule_value.getPortalType() in (
'Invoicing Rule', 'Invoice Rule'):
if self._getMatchingCell(movement) is not None: if self._getMatchingCell(movement) is not None:
return 1 return 1
return 0 return 0
...@@ -128,23 +129,35 @@ class InvoiceTransactionRule(Rule, XMLMatrix): ...@@ -128,23 +129,35 @@ class InvoiceTransactionRule(Rule, XMLMatrix):
# 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 [parent]+ simulation movement's deliveryValue # price_currency from the parents simulation movement's deliveryValue
# price_currency from the top level simulation movement's orderValue # price_currency from the top level simulation movement's orderValue
# FIXME: this must be discussed. for now we get the resource resource = None
# from the cell invoice_line = my_invoice_line_simulation.getDeliveryValue()
#invoice_line = my_invoice_line_simulation.getDeliveryValue() if invoice_line is not None :
#invoice = invoice_line.getExplanationValue() invoice = invoice_line.getExplanationValue()
#resource = None if invoice.getResource() is not None :
#if 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:
# search the resource on parents simulation movement's deliveries
# still TODO: search resource on parents (Order, Packing List ...) simulation_movement = applied_rule.getParent()
#if resource is None : portal_simulation = self.getPortal().portal_simulation
# LOG("InvoiceTransactionRule", PROBLEM, while resource is None and simulation_movement != portal_simulation :
# "Unable to expand %s: no resource"%applied_rule.getPath()) delivery = simulation_movement.getDeliveryValue()
if hasattr(delivery, 'getPriceCurrency') and \
delivery.getPriceCurrency() is not None :
resource = delivery.getPriceCurrency()
if simulation_movement.getParent().getParent() \
== portal_simulation :
# we are on the first simulation movement,
# we'll try to get the resource from it's order.
order = simulation_movement.getOrderValue()
if hasattr(order, 'getPriceCurrency') and \
order.getPriceCurrency() is not None :
resource = order.getPriceCurrency()
simulation_movement = simulation_movement.getParent().getParent()
# Add every movement from the Matrix to the Simulation # Add every movement from the Matrix to the Simulation
for transaction_line in my_cell.objectValues() : for transaction_line in my_cell.objectValues() :
...@@ -152,15 +165,18 @@ class InvoiceTransactionRule(Rule, XMLMatrix): ...@@ -152,15 +165,18 @@ class InvoiceTransactionRule(Rule, XMLMatrix):
simulation_movement = applied_rule[transaction_line.getId()] simulation_movement = applied_rule[transaction_line.getId()]
else : else :
simulation_movement = applied_rule.newContent( simulation_movement = applied_rule.newContent(
portal_type=invoice_transaction_line_type) id = transaction_line.getId()
, portal_type=invoice_transaction_line_type)
resource = transaction_line.getResource() or my_cell.getResource()
if resource in (None, '') : if resource is None :
LOG("InvoiceTransactionRule", PROBLEM, # last resort : get the resource from the rule
"Unable to expand %s: no resource"%applied_rule.getPath()) resource = transaction_line.getResource() or my_cell.getResource()
raise ValueError, 'no resource for %s' % \ if resource in (None, '') :
LOG("InvoiceTransactionRule", PROBLEM,
"Unable to expand %s: no resource"%applied_rule.getPath())
raise ValueError, 'no resource for %s' % \
transaction_line.getPath() transaction_line.getPath()
simulation_movement._edit( 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()
...@@ -175,14 +191,10 @@ class InvoiceTransactionRule(Rule, XMLMatrix): ...@@ -175,14 +191,10 @@ class InvoiceTransactionRule(Rule, XMLMatrix):
, stop_date = my_invoice_line_simulation.getStopDate() , stop_date = my_invoice_line_simulation.getStopDate()
, force_update = 1 , force_update = 1
) )
# Now we can set the last expand simulation state to the current state
#XXX Note : this is wrong, as there isn't always a sale invoice when we expand this rule.
#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') security.declareProtected(Permissions.ModifyPortalContent, 'solve')
def solve(self, applied_rule, solution_list): def solve(self, applied_rule, solution_list):
""" """
......
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