Commit 4923ce56 authored by Jérome Perrin's avatar Jérome Perrin

Inventory API: expose more brain properties

parent 8e7737c1
...@@ -92,7 +92,7 @@ class InventoryListBrain(ComputedAttributeGetItemCompatibleMixin): ...@@ -92,7 +92,7 @@ class InventoryListBrain(ComputedAttributeGetItemCompatibleMixin):
return uid_cache[uid] return uid_cache[uid]
except KeyError: except KeyError:
result_list = self.portal_catalog.unrestrictedSearchResults(uid=uid, limit=1, result_list = self.portal_catalog.unrestrictedSearchResults(uid=uid, limit=1,
select_dict=dict(title=None, relative_url=None)) select_dict=dict(title=None, relative_url=None, reference=None))
result = None result = None
if result_list: if result_list:
result = result_list[0] result = result_list[0]
...@@ -123,6 +123,12 @@ class InventoryListBrain(ComputedAttributeGetItemCompatibleMixin): ...@@ -123,6 +123,12 @@ class InventoryListBrain(ComputedAttributeGetItemCompatibleMixin):
return node.title return node.title
node_title = ComputedAttribute(getNodeTitle, 1) node_title = ComputedAttribute(getNodeTitle, 1)
def getNodeTranslatedTitle(self):
node = self.getNodeValue()
if node is not None:
return node.getObject().getTranslatedTitle()
node_translated_title = ComputedAttribute(getNodeTranslatedTitle, 1)
def getNodeRelativeUrl(self): def getNodeRelativeUrl(self):
node = self.getNodeValue() node = self.getNodeValue()
if node is not None: if node is not None:
...@@ -138,6 +144,12 @@ class InventoryListBrain(ComputedAttributeGetItemCompatibleMixin): ...@@ -138,6 +144,12 @@ class InventoryListBrain(ComputedAttributeGetItemCompatibleMixin):
return resource.title return resource.title
resource_title = ComputedAttribute(getResourceTitle, 1) resource_title = ComputedAttribute(getResourceTitle, 1)
def getResourceTranslatedTitle(self):
resource = self.getResourceValue()
if resource is not None:
return resource.getObject().getTranslatedTitle()
resource_translated_title = ComputedAttribute(getResourceTranslatedTitle, 1)
def getResourceRelativeUrl(self): def getResourceRelativeUrl(self):
resource = self.getResourceValue() resource = self.getResourceValue()
if resource is not None: if resource is not None:
...@@ -147,7 +159,7 @@ class InventoryListBrain(ComputedAttributeGetItemCompatibleMixin): ...@@ -147,7 +159,7 @@ class InventoryListBrain(ComputedAttributeGetItemCompatibleMixin):
def getResourceReference(self): def getResourceReference(self):
resource = self.getResourceValue() resource = self.getResourceValue()
if resource is not None: if resource is not None:
return resource.getReference() return resource.reference
resource_reference = ComputedAttribute(getResourceReference, 1) resource_reference = ComputedAttribute(getResourceReference, 1)
def getListItemUrl(self, cname_id, selection_index, selection_name): def getListItemUrl(self, cname_id, selection_index, selection_name):
...@@ -326,6 +338,21 @@ class MovementHistoryListBrain(InventoryListBrain): ...@@ -326,6 +338,21 @@ class MovementHistoryListBrain(InventoryListBrain):
return explanation.absolute_url() return explanation.absolute_url()
return '' return ''
def getMirrorSectionValue(self):
return self._getObjectByUid(self.mirror_section_uid)
def getMirrorSectionTitle(self):
mirror_section = self.getMirrorSectionValue()
if mirror_section is not None:
return mirror_section.title
mirror_section_title = ComputedAttribute(getMirrorSectionTitle, 1)
def getMirrorSectionRelativeUrl(self):
mirror_section = self.getMirrorSectionValue()
if mirror_section is not None:
return mirror_section.relative_url
mirror_section_relative_url = ComputedAttribute(getMirrorSectionRelativeUrl, 1)
def _debit(self): def _debit(self):
if self.is_cancellation: if self.is_cancellation:
return min(self.total_quantity, 0) return min(self.total_quantity, 0)
......
...@@ -1484,20 +1484,34 @@ class TestMovementHistoryList(InventoryAPITestCase): ...@@ -1484,20 +1484,34 @@ class TestMovementHistoryList(InventoryAPITestCase):
self.assertTrue(hasattr(brain, 'mirror_node_uid')) self.assertTrue(hasattr(brain, 'mirror_node_uid'))
self.assertTrue(hasattr(brain, 'mirror_section_uid')) self.assertTrue(hasattr(brain, 'mirror_section_uid'))
# compatiblity names
self.assertTrue(hasattr(brain, 'section_title')) self.assertTrue(hasattr(brain, 'section_title'))
self.assertEqual(brain.section_title, self.section.getTitle()) self.assertEqual(brain.section_title, self.section.getTitle())
self.assertTrue(hasattr(brain, 'section_relative_url')) self.assertTrue(hasattr(brain, 'section_relative_url'))
self.assertEqual(brain.section_relative_url, self.section.getRelativeUrl()) self.assertEqual(brain.section_relative_url, self.section.getRelativeUrl())
self.assertTrue(hasattr(brain, 'mirror_section_title'))
self.assertEqual(brain.mirror_section_title, self.mirror_section.getTitle())
self.assertTrue(hasattr(brain, 'mirror_section_relative_url'))
self.assertEqual(brain.mirror_section_relative_url,
self.mirror_section.getRelativeUrl())
self.assertTrue(hasattr(brain, 'node_title')) self.assertTrue(hasattr(brain, 'node_title'))
self.assertEqual(brain.node_title, self.node.getTitle()) self.assertEqual(brain.node_title, self.node.getTitle())
self.assertTrue(hasattr(brain, 'node_translated_title'))
self.assertEqual(brain.node_title, self.node.getTranslatedTitle())
self.assertTrue(hasattr(brain, 'node_relative_url')) self.assertTrue(hasattr(brain, 'node_relative_url'))
self.assertEqual(brain.node_relative_url, self.node.getRelativeUrl()) self.assertEqual(brain.node_relative_url, self.node.getRelativeUrl())
self.assertTrue(hasattr(brain, 'resource_title')) self.assertTrue(hasattr(brain, 'resource_title'))
self.assertEqual(brain.resource_title, self.resource.getTitle()) self.assertEqual(brain.resource_title, self.resource.getTitle())
self.assertTrue(hasattr(brain, 'resource_translated_title'))
self.assertEqual(brain.resource_title, self.resource.getTranslatedTitle())
self.assertTrue(hasattr(brain, 'resource_reference'))
self.assertEqual(brain.resource_reference, self.resource.getReference())
self.assertTrue(hasattr(brain, 'resource_relative_url')) self.assertTrue(hasattr(brain, 'resource_relative_url'))
self.assertEqual(brain.resource_relative_url, self.resource.getRelativeUrl()) self.assertEqual(brain.resource_relative_url, self.resource.getRelativeUrl())
def testBrainGetItem(self): def testBrainGetItem(self):
"""Test __getitem__ interface on brains.""" """Test __getitem__ interface on brains."""
getMovementHistoryList = self.getSimulationTool().getMovementHistoryList 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