Commit 264b69f4 authored by Jérome Perrin's avatar Jérome Perrin

Item_getTrackingList assorted cleanups

backport nexedi/erp5/merge_requests/469 to fix [Tracking issue for a specific user](https://www.erp5.com/project_section/capago-project/forum/Tracking-issue-for-a-specific-user-NfPPKu12hc)




/reviewed-on https://lab.nexedi.com/nexedi/erp5-capago/merge_requests/3
parents e7b009a7 bca27371
from Products.ERP5Type.Document import newTempBase from Products.ERP5Type.Document import newTempBase
portal = context.getPortalObject() portal = context.getPortalObject()
catalog = portal.portal_catalog.getResultValue
if current: if current:
method = portal.portal_simulation.getCurrentTrackingList method = portal.portal_simulation.getCurrentTrackingList
else: else:
method = portal.portal_simulation.getTrackingList method = portal.portal_simulation.getTrackingList
uid = context.getUid() # tracking list is much more readable if locations are sorted by dates.
kw.setdefault('sort_on', (('date', 'ascending',),))
history_list = [] history_list = []
for brain in method(aggregate_uid=context.getUid(), **kw):
for res in method(aggregate_uid=uid, **kw):
history = newTempBase(context, str(len(history_list))) history = newTempBase(context, str(len(history_list)))
explanation = catalog(uid=res.delivery_uid) explanation = brain.getExplanationValue()
node_value = catalog(uid=res.node_uid) date = brain.getDate()
section_value = catalog(uid=res.section_uid)
resource_value = catalog(uid=res.resource_uid)
history.edit( history.edit(
#uid = catalog(uid=res.uid).getTitle(), date=date,
date=res.getDate(), node_title=brain.node_title,
node_title=node_value is not None and node_value.getTitle() or None,
source_title=explanation.getSourceTitle(), source_title=explanation.getSourceTitle(),
section_title=section_value is not None and section_value.getTitle() or None, section_title=brain.section_title,
resource_title=resource_value is not None and resource_value.getTitle() or None, resource_title=brain.resource_title,
explanation=explanation.getTitle(), explanation=explanation.getTitle(),
translated_portal_type = explanation.getTranslatedPortalType(), translated_portal_type=explanation.getTranslatedPortalType(),
quantity = explanation.getQuantity(), quantity=explanation.getQuantity(),
url=explanation.absolute_url(), url=explanation.absolute_url(),
item_quantity = context.getQuantity(at_date=res.getDate()), # item_quantity=context.getQuantity(at_date=date),
variation_category_item_list = [x[0] for x in explanation.getVariationCategoryItemList()], variation_category_item_list=[x[0] for x in explanation.getVariationCategoryItemList()],
simulation_state=explanation.getTranslatedSimulationStateTitle(), simulation_state=explanation.getTranslatedSimulationStateTitle(),
) )
history_list.append(history) history_list.append(history)
return history_list return history_list
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<list> <list>
<string>columns</string> <string>columns</string>
<string>list_method</string> <string>list_method</string>
<string>sort</string> <string>sort_columns</string>
<string>title</string> <string>title</string>
<string>url_columns</string> <string>url_columns</string>
</list> </list>
...@@ -137,12 +137,20 @@ ...@@ -137,12 +137,20 @@
</value> </value>
</item> </item>
<item> <item>
<key> <string>sort</string> </key> <key> <string>sort_columns</string> </key>
<value> <value>
<list> <list>
<tuple>
<string>translated_portal_type</string>
<string>Type</string>
</tuple>
<tuple> <tuple>
<string>date</string> <string>date</string>
<string>ascending</string> <string>Date</string>
</tuple>
<tuple>
<string>simulation_state</string>
<string>State</string>
</tuple> </tuple>
</list> </list>
</value> </value>
......
...@@ -288,6 +288,9 @@ class TrackingListBrain(InventoryListBrain): ...@@ -288,6 +288,9 @@ class TrackingListBrain(InventoryListBrain):
""" """
List of aggregated movements List of aggregated movements
""" """
def getExplanationValue(self):
return self._getObjectByUid(self.delivery_uid)
def getDate(self): def getDate(self):
if not self.date: if not self.date:
return return
...@@ -296,8 +299,7 @@ class TrackingListBrain(InventoryListBrain): ...@@ -296,8 +299,7 @@ class TrackingListBrain(InventoryListBrain):
# the brain is accessed from the Shared.DC.ZRDB.Results.Results instance # the brain is accessed from the Shared.DC.ZRDB.Results.Results instance
obj = self.getObject() obj = self.getObject()
if obj is not None: if obj is not None:
portal = obj.getPortalObject() movement = self._getObjectByUid(self.delivery_uid)
movement = portal.portal_catalog.getObject(self.delivery_uid)
date = movement.getStartDate() or movement.getStopDate() date = movement.getStartDate() or movement.getStopDate()
if date is not None: if date is not None:
timezone = date.timezone() timezone = date.timezone()
......
...@@ -1095,6 +1095,46 @@ class TestItemScripts(ERP5TypeTestCase): ...@@ -1095,6 +1095,46 @@ class TestItemScripts(ERP5TypeTestCase):
self.assertEqual(None, self.assertEqual(None,
self.item.Item_getCurrentSiteTitle(at_date=DateTime() - 2)) self.item.Item_getCurrentSiteTitle(at_date=DateTime() - 2))
def test_Item_getTrackingList_empty(self):
self.assertEqual([], self.item.Item_getTrackingList())
def test_Item_getTrackingList_explanation_brain_attribute(self):
line = self._makeSalePackingListLine(start_date=DateTime(2001, 2, 3))
line.setTitle('explanation title')
self.tic()
history_item, = self.item.Item_getTrackingList()
self.assertEqual(DateTime(2001, 2, 3), history_item.date)
self.assertEqual('Node', history_item.node_title)
self.assertEqual('Mirror Node', history_item.source_title)
self.assertEqual('Section', history_item.section_title)
self.assertEqual('Product', history_item.resource_title)
self.assertEqual('explanation title', history_item.explanation)
self.assertEqual('Sale Packing List Line', history_item.translated_portal_type)
self.assertEqual(1, history_item.quantity)
self.assertEqual(line.absolute_url(), history_item.url)
self.assertEqual((), history_item.variation_category_item_list)
self.assertEqual('Delivered', history_item.simulation_state)
def test_Item_getTrackingList_default_sort(self):
# Item_getTrackingList returns lines sorted in chronological order
implicit_movement = self.portal.implicit_item_movement_module.newContent(
portal_type='Implicit Item Movement',
destination_value=self.mirror_node,
destination_section_value=self.mirror_section,
stop_date=DateTime(2016, 1, 1),
aggregate_value=self.item,
)
implicit_movement.deliver()
self._makeSalePackingListLine(start_date=DateTime(2017, 1, 1))
self.assertEqual(
[DateTime(2016, 1, 1), DateTime(2017, 1, 1)],
[brain.date for brain in self.item.Item_getTrackingList()])
self.assertEqual(
['Mirror Node', 'Node'],
[brain.node_title for brain in self.item.Item_getTrackingList()])
def test_item_current_location_and_transit_movement(self): def test_item_current_location_and_transit_movement(self):
# a started packing list is still in transit, so we do not know its # a started packing list is still in transit, so we do not know its
# current location until it is delivered. # current location until it is delivered.
......
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