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
from Products.ERP5.Document.Path import Path
from Products.ERP5.AggregatedAmountList import AggregatedAmountList
from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
import zope.interface
......@@ -387,17 +388,27 @@ class TradeCondition(Path, Transformation, XMLMatrix):
reference = self.getReference()
if not reference or (start_date is None and stop_date is None):
return self
effective_model_list = []
model_object_list = [result.getObject() for result in \
self.portal_catalog(portal_type=self.portal_type,
reference=reference,
sort_on=(('version','descending'),),
effective_date="<=%s"%start_date,
expiration_date=">=%s"%stop_date,
limit=1)]
if len(model_object_list):
return model_object_list[0]
return None
return self.getPortalObject().portal_catalog.unrestrictedGetResultValue(
query=ComplexQuery(
ComplexQuery(
Query(effective_date=None),
Query(effective_date=start_date,
range='ngt'),
logical_operator='OR'),
ComplexQuery(
Query(expiration_date=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,
'getModelIneritanceEffectiveProperty')
......
......@@ -1822,6 +1822,37 @@ class TestEffectiveTradeCondition(TradeConditionTestCase):
start_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):
# when no reference defined, getEffectiveModel returns the trade condition.
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