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

when no effective/expiration date is set for the trade condition, it means no

constraint for that date.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28352 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 545e8d9d
...@@ -37,6 +37,7 @@ from Products.ERP5.Document.Transformation import Transformation ...@@ -37,6 +37,7 @@ from Products.ERP5.Document.Transformation import Transformation
from Products.ERP5.Document.Path import Path from Products.ERP5.Document.Path import Path
from Products.ERP5.AggregatedAmountList import AggregatedAmountList from Products.ERP5.AggregatedAmountList import AggregatedAmountList
from Products.ERP5Type.XMLMatrix import XMLMatrix from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
import zope.interface import zope.interface
...@@ -387,17 +388,27 @@ class TradeCondition(Path, Transformation, XMLMatrix): ...@@ -387,17 +388,27 @@ class TradeCondition(Path, Transformation, XMLMatrix):
reference = self.getReference() reference = self.getReference()
if not reference or (start_date is None and stop_date is None): if not reference or (start_date is None and stop_date is None):
return self return self
effective_model_list = []
model_object_list = [result.getObject() for result in \ return self.getPortalObject().portal_catalog.unrestrictedGetResultValue(
self.portal_catalog(portal_type=self.portal_type, query=ComplexQuery(
reference=reference, ComplexQuery(
sort_on=(('version','descending'),), Query(effective_date=None),
effective_date="<=%s"%start_date, Query(effective_date=start_date,
expiration_date=">=%s"%stop_date, range='ngt'),
limit=1)] logical_operator='OR'),
if len(model_object_list): ComplexQuery(
return model_object_list[0] Query(expiration_date=None),
return None Query(expiration_date=stop_date,
range='min'),
logical_operator='OR'),
Query(reference=reference),
Query(validation_state=(
'deleted', 'invalidated'),
operator='NOT'),
Query(portal_type=self.getPortalType()),
logical_operator='AND'),
sort_on=(('version','descending'),))
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getModelIneritanceEffectiveProperty') 'getModelIneritanceEffectiveProperty')
......
...@@ -1822,6 +1822,37 @@ class TestEffectiveTradeCondition(TradeConditionTestCase): ...@@ -1822,6 +1822,37 @@ class TestEffectiveTradeCondition(TradeConditionTestCase):
start_date=DateTime('2009/06/01'), start_date=DateTime('2009/06/01'),
stop_date=DateTime('2009/06/01'))) stop_date=DateTime('2009/06/01')))
def test_getEffectiveModel_without_dates(self):
# a trade condition without effective / expiration date is effective
self.trade_condition.setReference(self.id())
self.trade_condition.setEffectiveDate(None)
self.trade_condition.setExpirationDate(None)
transaction.commit()
self.tic()
self.assertEquals(self.trade_condition,
self.trade_condition.getEffectiveModel(
start_date=DateTime('2009/06/01'),
stop_date=DateTime('2009/06/01')))
self.trade_condition.setEffectiveDate(None)
self.trade_condition.setExpirationDate('2009/12/31')
transaction.commit()
self.tic()
self.assertEquals(self.trade_condition,
self.trade_condition.getEffectiveModel(
start_date=DateTime('2009/06/01'),
stop_date=DateTime('2009/06/01')))
self.trade_condition.setEffectiveDate('2009/01/01')
self.trade_condition.setExpirationDate(None)
transaction.commit()
self.tic()
self.assertEquals(self.trade_condition,
self.trade_condition.getEffectiveModel(
start_date=DateTime('2009/06/01'),
stop_date=DateTime('2009/06/01')))
def test_getEffectiveModel_return_self_when_no_reference(self): def test_getEffectiveModel_return_self_when_no_reference(self):
# when no reference defined, getEffectiveModel returns the trade condition. # when no reference defined, getEffectiveModel returns the trade condition.
self.trade_condition.setReference(None) self.trade_condition.setReference(None)
......
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