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
portal = context.getPortalObject()
catalog = portal.portal_catalog.getResultValue
if current:
method = portal.portal_simulation.getCurrentTrackingList
else:
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 = []
for res in method(aggregate_uid=uid, **kw):
for brain in method(aggregate_uid=context.getUid(), **kw):
history = newTempBase(context, str(len(history_list)))
explanation = catalog(uid=res.delivery_uid)
node_value = catalog(uid=res.node_uid)
section_value = catalog(uid=res.section_uid)
resource_value = catalog(uid=res.resource_uid)
explanation = brain.getExplanationValue()
date = brain.getDate()
history.edit(
#uid = catalog(uid=res.uid).getTitle(),
date=res.getDate(),
node_title=node_value is not None and node_value.getTitle() or None,
date=date,
node_title=brain.node_title,
source_title=explanation.getSourceTitle(),
section_title=section_value is not None and section_value.getTitle() or None,
resource_title=resource_value is not None and resource_value.getTitle() or None,
section_title=brain.section_title,
resource_title=brain.resource_title,
explanation=explanation.getTitle(),
translated_portal_type = explanation.getTranslatedPortalType(),
quantity = explanation.getQuantity(),
translated_portal_type=explanation.getTranslatedPortalType(),
quantity=explanation.getQuantity(),
url=explanation.absolute_url(),
item_quantity = context.getQuantity(at_date=res.getDate()),
variation_category_item_list = [x[0] for x in explanation.getVariationCategoryItemList()],
# item_quantity=context.getQuantity(at_date=date),
variation_category_item_list=[x[0] for x in explanation.getVariationCategoryItemList()],
simulation_state=explanation.getTranslatedSimulationStateTitle(),
)
......
......@@ -12,7 +12,7 @@
<list>
<string>columns</string>
<string>list_method</string>
<string>sort</string>
<string>sort_columns</string>
<string>title</string>
<string>url_columns</string>
</list>
......@@ -137,12 +137,20 @@
</value>
</item>
<item>
<key> <string>sort</string> </key>
<key> <string>sort_columns</string> </key>
<value>
<list>
<tuple>
<string>translated_portal_type</string>
<string>Type</string>
</tuple>
<tuple>
<string>date</string>
<string>ascending</string>
<string>Date</string>
</tuple>
<tuple>
<string>simulation_state</string>
<string>State</string>
</tuple>
</list>
</value>
......
......@@ -288,6 +288,9 @@ class TrackingListBrain(InventoryListBrain):
"""
List of aggregated movements
"""
def getExplanationValue(self):
return self._getObjectByUid(self.delivery_uid)
def getDate(self):
if not self.date:
return
......@@ -296,8 +299,7 @@ class TrackingListBrain(InventoryListBrain):
# the brain is accessed from the Shared.DC.ZRDB.Results.Results instance
obj = self.getObject()
if obj is not None:
portal = obj.getPortalObject()
movement = portal.portal_catalog.getObject(self.delivery_uid)
movement = self._getObjectByUid(self.delivery_uid)
date = movement.getStartDate() or movement.getStopDate()
if date is not None:
timezone = date.timezone()
......
......@@ -1095,6 +1095,46 @@ class TestItemScripts(ERP5TypeTestCase):
self.assertEqual(None,
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):
# a started packing list is still in transit, so we do not know its
# 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