Commit 69fe3461 authored by Sebastien Robin's avatar Sebastien Robin

make searchPredicateList working with dates


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3221 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f0f94061
...@@ -95,26 +95,32 @@ class DomainTool(BaseTool): ...@@ -95,26 +95,32 @@ class DomainTool(BaseTool):
if range_property: if range_property:
# We have to check a range property # We have to check a range property
base_name = 'predicate.%s' % property base_name = 'predicate.%s' % property
LOG('searchPredicateList, getPath',0,context.getPath())
LOG('searchPredicateList, base_name',0,base_name)
LOG('searchPredicateList, property',0,property)
LOG('searchPredicateList, getProperty',0,context.getProperty(property))
value = context.getProperty(property) value = context.getProperty(property)
expression = ''
if value is None: if value is None:
expression_list.append('%s is NULL AND %s_range_min is NULL AND %s_range_max is NULL' expression += "%s is NULL AND %s_range_min is NULL AND %s_range_max is NULL" \
% ((base_name,)*3)) % ((base_name,)*3)
else: else:
expression = '%s is NULL AND %s_range_min is NULL AND %s_range_max is NULL ' % ((base_name,)*3) expression = "%s is NULL AND %s_range_min is NULL AND %s_range_max is NULL " % ((base_name,)*3)
expression += 'OR %s = %s ' % (base_name,value) expression += "OR %s = '%s' " % (base_name,value)
expression += 'OR %s_range_min <= %s AND %s_range_max is NULL ' \ expression += "OR %s_range_min <= '%s' AND %s_range_max is NULL " \
% (base_name,value,base_name) % (base_name,value,base_name)
expression += 'OR %s_range_min is NULL AND %s_range_max > %s ' \ expression += "OR %s_range_min is NULL AND %s_range_max > '%s' " \
% (base_name,base_name,value) % (base_name,base_name,value)
expression += 'OR %s_range_min <= %s AND %s_range_max > %s ' \ expression += "OR %s_range_min <= '%s' AND %s_range_max > '%s' " \
% (base_name,value,base_name,value) % (base_name,value,base_name,value)
expression_list.append(expression) expression = '( ' + expression + ' )'
expression_list.append(expression)
checked_column_list.append('%s' % property) checked_column_list.append('%s' % property)
checked_column_list.append('%s_range_min' % property) checked_column_list.append('%s_range_min' % property)
checked_column_list.append('%s_range_max' % property) checked_column_list.append('%s_range_max' % property)
# Add predicate.uid for automatic join # Add predicate.uid for automatic join
sql_kw['predicate.uid'] = '!=0' sql_kw['predicate.uid'] = '!=0'
where_expression = ' OR '.join(expression_list) where_expression = ' AND '.join(expression_list)
# Add category selection # Add category selection
category_list = context.getCategoryList() category_list = context.getCategoryList()
...@@ -129,6 +135,7 @@ class DomainTool(BaseTool): ...@@ -129,6 +135,7 @@ class DomainTool(BaseTool):
# Add predicate_category.uid for automatic join # Add predicate_category.uid for automatic join
sql_kw['predicate_category.uid'] = '!=0' sql_kw['predicate_category.uid'] = '!=0'
kw.update(sql_kw) kw.update(sql_kw)
LOG('searchPredicateList, kw',0,kw)
sql_result_list = portal_catalog.searchResults(**kw) sql_result_list = portal_catalog.searchResults(**kw)
if kw.has_key('src__') and kw['src__']: if kw.has_key('src__') and kw['src__']:
......
...@@ -171,13 +171,13 @@ class Test(ERP5TypeTestCase): ...@@ -171,13 +171,13 @@ class Test(ERP5TypeTestCase):
# Test with order line not none and predicate to identity # Test with order line not none and predicate to identity
order_line.setQuantity(45) order_line.setQuantity(45)
kw = {'portal_type':'Mapped Value'}
predicate.setCriterion('quantity',identity=45,min=None,max=None) predicate.setCriterion('quantity',identity=45,min=None,max=None)
predicate.immediateReindexObject() predicate.immediateReindexObject()
predicate_list = domain_tool.searchPredicateList(order_line,test=test) predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
#get_transaction().commit()
self.assertEquals(len(predicate_list),1) self.assertEquals(len(predicate_list),1)
order_line.setQuantity(40) order_line.setQuantity(40)
predicate_list = domain_tool.searchPredicateList(order_line,test=test) predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
self.assertEquals(len(predicate_list),0) self.assertEquals(len(predicate_list),0)
# Test with order line not none and predicate to min # Test with order line not none and predicate to min
...@@ -185,7 +185,7 @@ class Test(ERP5TypeTestCase): ...@@ -185,7 +185,7 @@ class Test(ERP5TypeTestCase):
predicate = self.getPredicate() predicate = self.getPredicate()
predicate.setCriterion('quantity',identity=None,min=30,max=None) predicate.setCriterion('quantity',identity=None,min=30,max=None)
predicate.immediateReindexObject() predicate.immediateReindexObject()
predicate_list = domain_tool.searchPredicateList(order_line,test=test) predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
self.assertEquals(len(predicate_list),1) self.assertEquals(len(predicate_list),1)
order_line.setQuantity(10) order_line.setQuantity(10)
predicate_list = domain_tool.searchPredicateList(order_line,test=test) predicate_list = domain_tool.searchPredicateList(order_line,test=test)
...@@ -196,10 +196,10 @@ class Test(ERP5TypeTestCase): ...@@ -196,10 +196,10 @@ class Test(ERP5TypeTestCase):
predicate = self.getPredicate() predicate = self.getPredicate()
predicate.setCriterion('quantity',identity=None,min=None,max=50) predicate.setCriterion('quantity',identity=None,min=None,max=50)
predicate.immediateReindexObject() predicate.immediateReindexObject()
predicate_list = domain_tool.searchPredicateList(order_line,test=test) predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
self.assertEquals(len(predicate_list),1) self.assertEquals(len(predicate_list),1)
order_line.setQuantity(60) order_line.setQuantity(60)
predicate_list = domain_tool.searchPredicateList(order_line,test=test) predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
self.assertEquals(len(predicate_list),0) self.assertEquals(len(predicate_list),0)
# Test with order line not none and predicate to min max # Test with order line not none and predicate to min max
...@@ -207,13 +207,13 @@ class Test(ERP5TypeTestCase): ...@@ -207,13 +207,13 @@ class Test(ERP5TypeTestCase):
predicate = self.getPredicate() predicate = self.getPredicate()
predicate.setCriterion('quantity',identity=None,min=30,max=50) predicate.setCriterion('quantity',identity=None,min=30,max=50)
predicate.immediateReindexObject() predicate.immediateReindexObject()
predicate_list = domain_tool.searchPredicateList(order_line,test=test) predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
self.assertEquals(len(predicate_list),0) self.assertEquals(len(predicate_list),0)
order_line.setQuantity(60) order_line.setQuantity(60)
predicate_list = domain_tool.searchPredicateList(order_line,test=test) predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
self.assertEquals(len(predicate_list),0) self.assertEquals(len(predicate_list),0)
order_line.setQuantity(45) order_line.setQuantity(45)
predicate_list = domain_tool.searchPredicateList(order_line,test=test) predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
self.assertEquals(len(predicate_list),1) self.assertEquals(len(predicate_list),1)
# Test with order line not none and predicate to min max # Test with order line not none and predicate to min max
...@@ -221,19 +221,38 @@ class Test(ERP5TypeTestCase): ...@@ -221,19 +221,38 @@ class Test(ERP5TypeTestCase):
predicate.setMembershipCriterionBaseCategoryList(['region']) predicate.setMembershipCriterionBaseCategoryList(['region'])
predicate.setMembershipCriterionCategoryList(['region/europe']) predicate.setMembershipCriterionCategoryList(['region/europe'])
predicate.immediateReindexObject() predicate.immediateReindexObject()
#get_transaction().commit() predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
predicate_list = domain_tool.searchPredicateList(order_line,test=test)
self.assertEquals(len(predicate_list),0) self.assertEquals(len(predicate_list),0)
order_line.setCategoryList(['region/africa']) order_line.setCategoryList(['region/africa'])
predicate_list = domain_tool.searchPredicateList(order_line,test=test) predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
self.assertEquals(len(predicate_list),0) self.assertEquals(len(predicate_list),0)
order_line.setCategoryList(['region/europe']) order_line.setCategoryList(['region/europe'])
predicate_list = domain_tool.searchPredicateList(order_line,test=test) predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
self.assertEquals(len(predicate_list),1) self.assertEquals(len(predicate_list),1)
order_line.setQuantity(60) order_line.setQuantity(60)
predicate_list = domain_tool.searchPredicateList(order_line,test=test) predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
self.assertEquals(len(predicate_list),0) self.assertEquals(len(predicate_list),0)
# Test with order line not none and predicate to date min and date max
kw = {'portal_type':'Supply Line'}
self.supply_line.setBasePrice(23)
self.supply_line.setPricedQuantity(1)
self.supply_line.setDefaultResourceValue(self.resource)
order_line.setDefaultResourceValue(self.resource)
date1 = DateTime('2005/04/08 10:47:26.388 GMT-4')
date2 = DateTime('2005/04/10 10:47:26.388 GMT-4')
self.supply_line.setStartDateRangeMin(date1)
self.supply_line.setStartDateRangeMax(date2)
self.supply_line.immediateReindexObject()
current_date = DateTime('2005/04/1 10:47:26.388 GMT-4')
order_line.setStartDate(current_date)
predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
self.assertEquals(len(predicate_list),0)
current_date = DateTime('2005/04/09 10:47:26.388 GMT-4')
order_line.setStartDate(current_date)
predicate_list = domain_tool.searchPredicateList(order_line,test=test,**kw)
self.assertEquals(len(predicate_list),1)
def test_01_SearchPredidateListWithNoTest(self, quiet=0, run=run_all_test): def test_01_SearchPredidateListWithNoTest(self, quiet=0, run=run_all_test):
if not run: return if not run: return
if not quiet: if not quiet:
...@@ -264,7 +283,6 @@ class Test(ERP5TypeTestCase): ...@@ -264,7 +283,6 @@ class Test(ERP5TypeTestCase):
domain_tool = self.getDomainTool() domain_tool = self.getDomainTool()
context = self.resource.asContext(categories=['resource/%s' % self.resource.getRelativeUrl()]) context = self.resource.asContext(categories=['resource/%s' % self.resource.getRelativeUrl()])
mapped_value = domain_tool.generateMappedValue(context) mapped_value = domain_tool.generateMappedValue(context)
#get_transaction().commit()
self.assertEquals(mapped_value.getBasePrice(),23) self.assertEquals(mapped_value.getBasePrice(),23)
def test_04_GenerateMappedValueWithRanges(self, quiet=0, run=run_all_test): def test_04_GenerateMappedValueWithRanges(self, quiet=0, run=run_all_test):
...@@ -340,7 +358,6 @@ class Test(ERP5TypeTestCase): ...@@ -340,7 +358,6 @@ class Test(ERP5TypeTestCase):
domain_tool = self.getDomainTool() domain_tool = self.getDomainTool()
context = self.resource.asContext(categories=['resource/%s' % self.resource.getRelativeUrl(),'variation/%s/blue' % self.resource.getRelativeUrl()]) context = self.resource.asContext(categories=['resource/%s' % self.resource.getRelativeUrl(),'variation/%s/blue' % self.resource.getRelativeUrl()])
mapped_value = domain_tool.generateMappedValue(context,sort_method=sort_method) mapped_value = domain_tool.generateMappedValue(context,sort_method=sort_method)
#get_transaction().commit()
self.assertEquals(mapped_value.getProperty('base_price'),45) self.assertEquals(mapped_value.getProperty('base_price'),45)
context = self.resource.asContext(categories=['resource/%s' % self.resource.getRelativeUrl(),'variation/%s/red' % self.resource.getRelativeUrl()]) context = self.resource.asContext(categories=['resource/%s' % self.resource.getRelativeUrl(),'variation/%s/red' % self.resource.getRelativeUrl()])
mapped_value = domain_tool.generateMappedValue(context,sort_method=sort_method) mapped_value = domain_tool.generateMappedValue(context,sort_method=sort_method)
......
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