Commit 73bce252 authored by Julien Muchembled's avatar Julien Muchembled

Look at trade phase on rule first and remove obsolete code in PaymentSimulationRule

If we leave PaymentSimulationRule as it is now, 2 Trade Model Path must be
created (for bank and payable), instead of 1.
Reenable payment rule in tests.

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@37612 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3c1db12c
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
<key> <string>categories</string> </key> <key> <string>categories</string> </key>
<value> <value>
<tuple> <tuple>
<string>trade_phase/default/invoicing</string> <string>trade_phase/default/accounting</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
...@@ -42,7 +42,9 @@ ...@@ -42,7 +42,9 @@
<item> <item>
<key> <string>categories</string> </key> <key> <string>categories</string> </key>
<value> <value>
<tuple/> <tuple>
<string>trade_phase/default/payment</string>
</tuple>
</value> </value>
</item> </item>
<item> <item>
...@@ -73,6 +75,10 @@ ...@@ -73,6 +75,10 @@
<key> <string>portal_type</string> </key> <key> <string>portal_type</string> </key>
<value> <string>Payment Simulation Rule</string> </value> <value> <string>Payment Simulation Rule</string> </value>
</item> </item>
<item>
<key> <string>same_total_quantity</string> </key>
<value> <int>0</int> </value>
</item>
<item> <item>
<key> <string>test_method_id</string> </key> <key> <string>test_method_id</string> </key>
<value> <value>
......
...@@ -155,10 +155,6 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin): ...@@ -155,10 +155,6 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin):
def _getInputMovementList(self, movement_list=None, rounding=False): def _getInputMovementList(self, movement_list=None, rounding=False):
simulation_movement = self._applied_rule.getParentValue() simulation_movement = self._applied_rule.getParentValue()
input_movement = simulation_movement.asContext( quantity = simulation_movement.getCorrectedQuantity() * \
quantity=simulation_movement.getCorrectedQuantity() * simulation_movement.getPrice(0.0)
simulation_movement.getPrice(0.0)) return (simulation_movement.asContext(quantity=quantity),)
# XXX trade_phase category should be added to Simulation Movements
input_movement._setCategoryMembership('trade_phase',
('default/accounting',))
return (input_movement,)
...@@ -89,53 +89,10 @@ class PaymentSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate ...@@ -89,53 +89,10 @@ class PaymentSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate
return (movement.getSource() is None or movement.getDestination() is None) return (movement.getSource() is None or movement.getDestination() is None)
class PaymentRuleMovementGenerator(MovementGeneratorMixin): class PaymentRuleMovementGenerator(MovementGeneratorMixin):
def getGeneratedMovementList(self, movement_list=None, rounding=False):
"""
Input movement list comes from parent.
XXX This implementation using Business Path, not Payment Condition.
"""
ret = []
rule = self._rule
for input_movement, business_path in self \
._getInputMovementAndPathTupleList(movement_list=movement_list, rounding=rounding):
# Payment Rule does not work with Business Path
if business_path is None:
continue
# Since we need to consider business_path only for bank movement,
# not for payable movement, we pass None as business_path here.
kw = self._getPropertyAndCategoryList(input_movement, None, rule)
kw.update({'order':None, 'delivery':None})
quantity = kw.pop('quantity', 0)
efficiency = business_path.getEfficiency()
if efficiency:
quantity *= efficiency
start_date = business_path.getExpectedStartDate(input_movement)
if start_date is not None:
kw.update({'start_date':start_date})
stop_date = business_path.getExpectedStopDate(input_movement)
if stop_date is not None:
kw.update({'stop_date':stop_date})
# one for payable
simulation_movement = self._applied_rule.newContent(
portal_type=RuleMixin.movement_type,
temp_object=True,
quantity=-quantity,
**kw)
ret.append(simulation_movement)
# one for bank
kw.update({'source':business_path.getSource(),
'destination':business_path.getDestination(),})
simulation_movement = self._applied_rule.newContent(
portal_type=RuleMixin.movement_type,
temp_object=True,
quantity=quantity,
**kw)
ret.append(simulation_movement)
return ret
def _getUpdatePropertyDict(self, input_movement): def _getUpdatePropertyDict(self, input_movement):
return {'delivery': None} return {'delivery': None,
'order': None} # XXX is it useful ?
def _getInputMovementList(self, movement_list=None, rounding=None): def _getInputMovementList(self, movement_list=None, rounding=None):
return [self._applied_rule.getParentValue(),] return [self._applied_rule.getParentValue(),]
...@@ -126,16 +126,14 @@ class MovementGeneratorMixin: ...@@ -126,16 +126,14 @@ class MovementGeneratorMixin:
return {'delivery': input_movement.getRelativeUrl()} return {'delivery': input_movement.getRelativeUrl()}
def _getTradePhaseList(self, input_movement, business_process): # XXX-JPS WEIRD def _getTradePhaseList(self, input_movement, business_process): # XXX-JPS WEIRD
movement_trade_phase = input_movement.getTradePhaseList()
if movement_trade_phase:
return movement_trade_phase
if self._trade_phase_list: if self._trade_phase_list:
return self._trade_phase_list return self._trade_phase_list
if self._rule is not None: if self._rule is not None:
trade_phase_list = self._rule.getTradePhaseList() trade_phase_list = self._rule.getTradePhaseList()
if trade_phase_list: if trade_phase_list:
return trade_phase_list return trade_phase_list
return business_process.getTradePhaseList() return input_movement.getTradePhaseList() or \
business_process.getTradePhaseList()
def _getInputMovementList(self, movement_list=None, rounding=None): #XXX-JPS should it be amount or movement ? def _getInputMovementList(self, movement_list=None, rounding=None): #XXX-JPS should it be amount or movement ?
raise NotImplementedError raise NotImplementedError
......
...@@ -174,14 +174,7 @@ class TestBPMMixin(ERP5TypeTestCase): ...@@ -174,14 +174,7 @@ class TestBPMMixin(ERP5TypeTestCase):
'asset/receivable/refundable_vat') 'asset/receivable/refundable_vat')
def afterSetUp(self): def afterSetUp(self):
rule_tool = self.getRuleTool() self.validateRules()
for rule in rule_tool.contentValues(
portal_type=rule_tool.getPortalRuleTypeList()):
if (rule.getId().startswith('new_') and
# XXX disable temporarily broken payment rule
rule.getId() != 'new_payment_simulation_rule' and
rule.getValidationState() != 'validated'):
rule.validate()
self.createCategories() self.createCategories()
self.createAndValidateAccounts() self.createAndValidateAccounts()
self.stepTic() self.stepTic()
......
...@@ -119,15 +119,6 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase): ...@@ -119,15 +119,6 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
'solve_divergence_action', 'solve_divergence_action',
**kw) **kw)
def validateRules(self):
"""Enable all rules except temporarily broken payment rule"""
rule_tool = self.getRuleTool()
for rule in rule_tool.contentValues(
portal_type=rule_tool.getPortalRuleTypeList()):
if rule.getId() != 'new_payment_simulation_rule' and \
rule.getValidationState() != 'validated':
rule.validate()
def afterSetUp(self): def afterSetUp(self):
ERP5TypeTestCase.login(self) ERP5TypeTestCase.login(self)
self.createCategories() self.createCategories()
......
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