add trade_phase predicates to rules and check that already applied rules are...

add trade_phase predicates to rules and check that already applied rules are not rejected just because of that

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@45578 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5c2c470f
...@@ -54,6 +54,9 @@ class TestRuleMixin(TestOrderMixin): ...@@ -54,6 +54,9 @@ class TestRuleMixin(TestOrderMixin):
assert rule.getVersion().startswith('testRule.') assert rule.getVersion().startswith('testRule.')
return rule return rule
def _wipe(self, folder):
folder.manage_delObjects(list(folder.objectIds()))
def afterSetUp(self): def afterSetUp(self):
# delete rules # delete rules
rule_tool = self.portal.portal_rules rule_tool = self.portal.portal_rules
...@@ -76,16 +79,15 @@ class TestRuleMixin(TestOrderMixin): ...@@ -76,16 +79,15 @@ class TestRuleMixin(TestOrderMixin):
else: else:
self.pl = pl_module.objectValues()[0] self.pl = pl_module.objectValues()[0]
#delete applied_rule #delete applied_rule
self.getSimulationTool().manage_delObjects( self._wipe(self.getSimulationTool())
ids=list(self.getSimulationTool().objectIds()))
# commit # commit
transaction.commit() transaction.commit()
self.tic() self.tic()
def beforeTearDown(self): def beforeTearDown(self):
module = self.getSimulationTool() self._wipe(self.getSimulationTool())
module.manage_delObjects(list(module.objectIds())) self._wipe(self.portal.portal_skins.custom)
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -375,14 +377,21 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -375,14 +377,21 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
""" """
if not run: return if not run: return
skin_folder = self.getPortal().portal_skins.custom skin_folder = self.portal.portal_skins.custom
skin = createZODBPythonScript(skin_folder, 'delivery_rule_script', 'rule', createZODBPythonScript(skin_folder, 'delivery_rule_script', 'rule',
"return False") "return False")
createZODBPythonScript(skin_folder, 'invoice_rule_script', 'rule',
skin_folder = self.getPortal().portal_skins.custom
skin = createZODBPythonScript(skin_folder, 'invoice_rule_script', 'rule',
"return context.getParentValue().getSpecialiseReference() == 'default_delivery_rule'") "return context.getParentValue().getSpecialiseReference() == 'default_delivery_rule'")
# XXX-Leo: This script should become the default in erp5_simulation. Remove
# it from here when no longer needed:
createZODBPythonScript(skin_folder, 'RuleMixin_asPredicate', '',
"""
kw = dict(criterion_property_list=("start_date",),
membership_criterion_base_category_list=('trade_phase',),)
return context.generatePredicate(**kw)
""".strip())
delivery_rule = self.getRule('default_delivery_rule') delivery_rule = self.getRule('default_delivery_rule')
delivery_rule.validate() delivery_rule.validate()
...@@ -425,9 +434,9 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -425,9 +434,9 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
self.assertEquals(root_applied_rule.objectCount(), 1) self.assertEquals(root_applied_rule.objectCount(), 1)
movement = root_applied_rule.objectValues()[0] movement = root_applied_rule.objectValues()[0]
self.assertEquals(movement.objectCount(), 1) self.assertEquals(movement.objectCount(), 1)
applied_rule = movement.objectValues()[0] invoicing_rule_1_applied_rule = movement.objectValues()[0]
self.assertEquals(applied_rule.getSpecialise(), self.assertEquals(invoicing_rule_1_applied_rule.getSpecialise(),
invoicing_rule_1.getRelativeUrl()) invoicing_rule_1.getRelativeUrl())
# add more invoicing_rule and test that nothing is changed # add more invoicing_rule and test that nothing is changed
## same reference, higher version ## same reference, higher version
...@@ -457,8 +466,13 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -457,8 +466,13 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
self.assertEquals(movement.objectCount(), 2) self.assertEquals(movement.objectCount(), 2)
applied_rule_list = sorted(movement.objectValues(), applied_rule_list = sorted(movement.objectValues(),
key=lambda x: x.getSpecialiseValue().getReference()) key=lambda x: x.getSpecialiseValue().getReference())
# check the 1st applied rule is an application of invoicing_rule_1
self.assertEquals(applied_rule_list[0].getSpecialise(), self.assertEquals(applied_rule_list[0].getSpecialise(),
invoicing_rule_1.getRelativeUrl()) invoicing_rule_1.getRelativeUrl())
# but also check it's the same applied rule as before instead of a new
# one with the same specialization
self.assertEqual(applied_rule_list[0],
invoicing_rule_1_applied_rule)
self.assertEquals(applied_rule_list[1].getSpecialise(), self.assertEquals(applied_rule_list[1].getSpecialise(),
invoicing_rule_2.getRelativeUrl()) invoicing_rule_2.getRelativeUrl())
......
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