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

Since we store movement dates converted in UTC, 'date' attribute on brains

returned by getMovementHistoryList were returned as UTC.
This patch convert dates to the original timezone.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18666 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 50e5d0f4
......@@ -342,3 +342,22 @@ class DeliveryListBrain(InventoryListBrain):
list(self.getPortalFutureInventoryStateList()) + \
list(self.getPortalReservedInventoryStateList()) + \
list(self.getPortalCurrentInventoryStateList()))
class MovementHistoryListBrain(InventoryListBrain):
"""Brain for getMovementHistoryList
"""
def __init__(self):
if not self.date:
return
# convert the date in the movement's original timezone.
# This is a somehow heavy operation, but fortunatly it's only called when
# the brain is accessed from the Shared.DC.ZRDB.Results.Results instance
obj = self.getObject()
if obj is not None:
if self.node_relative_url == obj.getSource():
timezone = obj.getStartDate().timezone()
else:
timezone = obj.getStopDate().timezone()
self.date = self.date.toZone(timezone)
......@@ -626,7 +626,7 @@ precision</string> </value>
</item>
<item>
<key> <string>class_name_</string> </key>
<value> <string>InventoryListBrain</string> </value>
<value> <string>MovementHistoryListBrain</string> </value>
</item>
<item>
<key> <string>connection_hook</string> </key>
......
......@@ -842,7 +842,7 @@ class TestMovementHistoryList(InventoryAPITestCase):
# maybe this check is too low level (Shared/DC/ZRDB//Results.py, class r)
r_bases = getMovementHistoryList()._class.__bases__
brain_class = r_bases[2].__name__
self.assertEquals('InventoryListBrain', brain_class,
self.assertEquals('MovementHistoryListBrain', brain_class,
"unexpected brain class for getMovementHistoryList InventoryListBrain"
" != %s (bases %s)" % (brain_class, r_bases))
......@@ -1103,6 +1103,39 @@ class TestMovementHistoryList(InventoryAPITestCase):
from_date=DateTime(2006, 01, 02),
to_date=DateTime(2006, 01, 03),
section_uid=self.mirror_section.getUid())), 1)
def test_BrainDateTimeZone(self):
getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
self._makeMovement(quantity=100,
start_date=DateTime('2001/02/03 04:05 GMT+3'))
movement_history_list = getMovementHistoryList(
section_uid=self.section.getUid())
self.assertEquals(len(movement_history_list), 1)
brain = movement_history_list[0]
self.assertEquals(DateTime('2001/02/03 04:05 GMT+3'), brain.date)
self.assertEquals('GMT+3', brain.date.timezone())
def test_BrainDateTimeZoneStopDate(self):
getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
self._makeMovement(quantity=100,
start_date=DateTime('2001/02/03 04:05 GMT+2'),
stop_date=DateTime('2001/02/03 04:05 GMT+3'))
movement_history_list = getMovementHistoryList(
mirror_section_uid=self.section.getUid())
self.assertEquals(len(movement_history_list), 1)
brain = movement_history_list[0]
self.assertEquals(DateTime('2001/02/03 04:05 GMT+2'), brain.date)
self.assertEquals('GMT+2', brain.date.timezone())
def test_BrainEmptyDate(self):
getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
self._makeMovement(quantity=100,)
movement_history_list = getMovementHistoryList(
section_uid=self.section.getUid())
self.assertEquals(len(movement_history_list), 1)
brain = movement_history_list[0]
self.assertEquals(None, brain.date)
def test_SortOnDate(self):
getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
......
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