Commit 39ad1e16 authored by Ayush Tiwari's avatar Ayush Tiwari

[erp5_core]: Add function to get item parameter dict in InventoryBrain to be used to create URL

parent 4267ba77
......@@ -173,38 +173,16 @@ class InventoryListBrain(ComputedAttributeGetItemCompatibleMixin):
return resource.reference
resource_reference = ComputedAttribute(getResourceReference, 1)
def getListItemUrl(self, cname_id, selection_index, selection_name):
"""Returns the URL for column `cname_id`. Used by ListBox
"""
resource = self.getResourceValue()
if cname_id in ('getExplanationText', 'getExplanation', ):
o = self.getObject()
if o is not None:
if not getattr(o, 'isDelivery', 0):
explanation = o.getExplanationValue()
else:
# Additional inventory movements are catalogged in stock table
# with the inventory's uid. Then they are their own explanation.
explanation = o
if explanation is not None:
return explanation.absolute_url()
return ''
elif resource is not None:
# A resource is defined, so try to display the movement list
form_id = 'Resource_viewMovementHistory'
def getListItemParamDict(self, cname_id, selection_index, selection_name):
query_kw = {
'variation_text': self.variation_text,
'selection_name': selection_name,
'selection_index': selection_index,
'domain_name': selection_name,
"node_uid": self.node_uid
'node_uid': self.node_uid
}
# Add parameters to query_kw
query_kw_update = {}
if cname_id in ('transformed_resource_title', ):
return resource.absolute_url()
elif cname_id in ('getCurrentInventory', ):
if cname_id == 'getCurrentInventory':
query_kw_update = {
'simulation_state':
list(self.getPortalCurrentInventoryStateList() + \
......@@ -214,7 +192,7 @@ class InventoryListBrain(ComputedAttributeGetItemCompatibleMixin):
self.getPortalTransitInventoryStateList())
}
elif cname_id in ('getAvailableInventory', ):
elif cname_id == 'getAvailableInventory':
query_kw_update = {
'simulation_state': list(self.getPortalCurrentInventoryStateList() + \
self.getPortalTransitInventoryStateList()),
......@@ -234,7 +212,7 @@ class InventoryListBrain(ComputedAttributeGetItemCompatibleMixin):
list(self.getPortalReservedInventoryStateList()) + \
list(self.getPortalCurrentInventoryStateList())
}
elif cname_id in ('getInventoryAtDate', ):
elif cname_id == 'getInventoryAtDate':
query_kw_update = {
'to_date': self.at_date,
'simulation_state': \
......@@ -242,9 +220,56 @@ class InventoryListBrain(ComputedAttributeGetItemCompatibleMixin):
list(self.getPortalReservedInventoryStateList())
}
query_kw.update(query_kw_update)
return '%s/%s?%s&reset=1' % ( resource.absolute_url(),
return query_kw
def getListItemUrlDict(self, cname_id, selection_index, selection_name):
"""
Returns url result dict for Inventory
"""
jio_key = self.getResourceValue().getRelativeUrl()
return {
'command': 'push_history',
'view_kw': {
'view': 'view_movement_history',
'jio_key': jio_key,
'extra_param_json': self.getListItemParamDict(cname_id,
selection_index,
selection_name)
},
'options': {
'jio_key': jio_key
}
}
def getListItemUrl(self, cname_id, selection_index, selection_name):
"""Returns the URL for column `cname_id`. Used by ListBox
"""
resource = self.getResourceValue()
if cname_id in ('getExplanationText', 'getExplanation', ):
o = self.getObject()
if o is not None:
if not getattr(o, 'isDelivery', 0):
explanation = o.getExplanationValue()
else:
# Additional inventory movements are catalogged in stock table
# with the inventory's uid. Then they are their own explanation.
explanation = o
if explanation is not None:
return explanation.absolute_url()
return ''
elif resource is not None:
if cname_id in ('transformed_resource_title', ):
return resource.absolute_url()
# A resource is defined, so try to display the movement list
form_id = 'Resource_viewMovementHistory'
query_kw = self.getListItemParamDict(cname_id,
selection_index,
selection_name
)
return '%s/%s?%s&reset=1' % (resource.absolute_url(),
form_id,
make_query(**query_kw) )
make_query(**query_kw))
# default case, if it's a movement, return link to the explanation of this
# movement.
......@@ -341,15 +366,29 @@ class MovementHistoryListBrain(InventoryListBrain):
return self._convertDateToZone(self.date_utc)
date = ComputedAttribute(_date, 1)
def getListItem(self, cname_id, selection_index, selection_name):
document = self.getObject()
if document.isMovement():
return document.getExplanationValue()
def getListItemUrlDict(self, cname_id, selection_index, selection_name):
return {
'command': 'push_history',
'options': {
'jio_key': self.getListItem(cname_id,
selection_index,
selection_name).getRelativeUrl(),
'view': 'view'
}
}
def getListItemUrl(self, cname_id, selection_index, selection_name):
"""Returns the URL for column `cname_id`. Used by ListBox
Here we just want a link to the explanation of movement.
"""
document = self.getObject()
if document.isMovement():
explanation = document.getExplanationValue()
if explanation is not None:
return explanation.absolute_url()
item = self.getListItem(cname_id, selection_index, selection_name)
if item is not None:
return item.absolute_url()
return ''
def _debit(self):
......
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