Commit 74ec3a70 authored by Romain Courteaud's avatar Romain Courteaud

Cleaned Coramy's code (getListItemUrl, getExplanationText).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5029 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d31f74bb
...@@ -118,12 +118,23 @@ class InventoryListBrain(ZSQLBrain): ...@@ -118,12 +118,23 @@ class InventoryListBrain(ZSQLBrain):
Returns current inventory Returns current inventory
""" """
simulation_tool = getToolByName(self,'portal_simulation') simulation_tool = getToolByName(self,'portal_simulation')
return simulation_tool.getAvailableInventory(node=self.node_relative_url,variation_text=self.variation_text, return simulation_tool.getAvailableInventory(
resource=self.resource_relative_url,**kw) node=self.node_relative_url,
variation_text=self.variation_text,
resource=self.resource_relative_url, **kw)
def getQuantity(self, **kw): def getQuantity(self, **kw):
result = self.Delivery_zGetTotal( resource_uid = [self.resource_uid], """
variation_text = self.variation_text) Return the quantity of the current delivery for a resource
"""
total_kw = {
'explanation_uid': self.getDeliveryUid(),
'resource_uid': self.resource_uid,
'variation_text': self.variation_text,
}
total_kw.update(self.portal_catalog.buildSQLQuery(query_table='movement',
**total_kw))
result = self.Delivery_zGetTotal(**total_kw)
inventory = None inventory = None
if len(result) > 0: if len(result) > 0:
inventory = result[0].inventory inventory = result[0].inventory
...@@ -134,61 +145,83 @@ class InventoryListBrain(ZSQLBrain): ...@@ -134,61 +145,83 @@ class InventoryListBrain(ZSQLBrain):
def getQuantityUnit(self, **kw): def getQuantityUnit(self, **kw):
try: try:
resource = self.portal_categories.unrestrictedTraverse(self.resource_relative_url) resource = self.portal_categories.unrestrictedTraverse(
self.resource_relative_url)
return resource.getQuantityUnit() return resource.getQuantityUnit()
except AttributeError: except AttributeError:
return '' return ''
def getListItemUrl(self, cname_id, selection_index, selection_name): def getListItemUrl(self, cname_id, selection_index, selection_name):
# XXX FIXME can catch to many exceptions
try: try:
if cname_id in ('getExplanationText','getExplanation', ): if cname_id in ('getExplanationText','getExplanation', ):
o = self.getObject() o = self.getObject()
if o is not None: if o is not None:
explanation = o.getExplanationValue() explanation = o.getExplanationValue()
if explanation is not None: if explanation is not None:
return '%s/%s' % (self.portal_url.getPortalObject().absolute_url(), explanation.getRelativeUrl()) return '%s/%s' % (self.portal_url.getPortalObject().absolute_url(),
explanation.getRelativeUrl())
else: else:
return '' return ''
elif cname_id in ('getAggregateList','getAggregateListText',): # XXX Coramy, to be deleted
kw = { # elif cname_id in ('getAggregateList','getAggregateListText',):
'list_method_id' : 'Resource_zGetAggregateList', # kw = {
'explanation_uid' : self.explanation_uid, # 'list_method_id' : 'Resource_zGetAggregateList',
'node_uid' : self.node_uid, # 'explanation_uid' : self.explanation_uid,
'section_uid' : self.section_uid, # 'node_uid' : self.node_uid,
'variation_text' : self.variation_text, # 'section_uid' : self.section_uid,
'resource_uid' : self.resource_uid, # 'variation_text' : self.variation_text,
'reset': 1 # 'resource_uid' : self.resource_uid,
# 'reset': 1
# }
# url_params_string = make_query(kw)
# # should be search XXX
# return '%s/piece_tissu?%s ' % (
# self.portal_url.getPortalObject().absolute_url(),
# url_params_string
# )
elif (self.resource_relative_url is not None):
# A resource is defined, so try to display the movement list
resource = self.portal_categories.unrestrictedTraverse(
self.resource_relative_url)
form_name = 'Resource_viewMovementHistory'
query_kw = {
'variation_text': self.variation_text,
'selection_name': selection_name,
'selection_index': selection_index,
} }
url_params_string = make_query(kw) # Add parameters to query_kw
# should be search XXX query_kw_update = {}
return '%s/piece_tissu?%s ' % ( if cname_id in ('getCurrentInventory', ):
self.portal_url.getPortalObject().absolute_url(), query_kw_update = {
url_params_string 'simulation_state': list(self.getPortalCurrentInventoryStateList())
) }
elif cname_id in ('getCurrentInventory',): elif cname_id in ('getAvailableInventory', ):
resource = self.portal_categories.unrestrictedTraverse(self.resource_relative_url) query_kw_update = {
return '%s/Resource_movementHistoryView?%s&reset=1' % (resource.absolute_url(), 'omit_simulation': 1,
make_query(variation_text=self.variation_text, selection_name=selection_name, selection_index=selection_index, 'omit_input': 1,
simulation_state=list(self.getPortalCurrentInventoryStateList()))) 'simulation_state': \
elif cname_id in ('getAvailableInventory',): list(self.getPortalReservedInventoryStateList())
resource = self.portal_categories.unrestrictedTraverse(self.resource_relative_url) }
return '%s/Resource_movementHistoryView?%s&reset=1' % (resource.absolute_url(), elif cname_id in ('getFutureInventory', 'inventory', ):
make_query(variation_text=self.variation_text, selection_name=selection_name, selection_index=selection_index,omit_simulation = 1, omit_input = 1, query_kw_update = {
simulation_state=list(self.getPortalReservedInventoryStateList()))) 'simulation_state': \
elif cname_id in ('getFutureInventory','inventory', ): list(self.getPortalFutureInventoryStateList()) + \
resource = self.portal_categories.unrestrictedTraverse(self.resource_relative_url) list(self.getPortalReservedInventoryStateList())
return '%s/Resource_movementHistoryView?%s&reset=1' % (resource.absolute_url(), }
make_query(variation_text=self.variation_text, elif cname_id in ('getInventoryAtDate', ):
selection_name=selection_name, selection_index=selection_index, simulation_state=list(self.getPortalFutureInventoryStateList())+list(self.getPortalReservedInventoryStateList()))) query_kw_update = {
elif cname_id in ('getInventoryAtDate',): 'to_date': self.at_date,
resource = self.portal_categories.unrestrictedTraverse(self.resource_relative_url) 'simulation_state': \
return '%s/Resource_movementHistoryView?%s&reset=1' % (resource.absolute_url(), list(self.getPortalFutureInventoryStateList()) + \
make_query(variation_text=self.variation_text, to_date=self.at_date, list(self.getPortalReservedInventoryStateList())
selection_name=selection_name, selection_index=selection_index, simulation_state=list(self.getPortalFutureInventoryStateList())+list(self.getPortalReservedInventoryStateList()))) }
else: query_kw.update(query_kw_update)
resource = self.portal_categories.unrestrictedTraverse(self.resource_relative_url) # Return result
return '%s/Resource_movementHistoryView?%s&reset=1' % (resource.absolute_url(), return '%s/%s?%s&reset=1' % (
make_query(variation_text=self.variation_text, selection_name=selection_name, selection_index=selection_index)) resource.absolute_url(),
form_name,
make_query(**query_kw))
except (AttributeError, KeyError): except (AttributeError, KeyError):
return '' return ''
...@@ -207,45 +240,19 @@ class InventoryListBrain(ZSQLBrain): ...@@ -207,45 +240,19 @@ class InventoryListBrain(ZSQLBrain):
def getExplanationText(self): def getExplanationText(self):
# Returns an explanation of the movement # Returns an explanation of the movement
o = self.getObject() o = self.getObject()
explanation_text = 'Unknow'
if o is not None: if o is not None:
portal_type = o.getPortalType() # Get the delivery/order
if portal_type == "Simulation Movement":
order = o.getExplanationValue()
if order is not None:
if order.getPortalType() == 'Sales Order' :
return "%s %s %s" % ('Commande vente', order.getId(), order.getDestinationDecisionOrganisationTitle())
elif order.getPortalType() == 'Purchase Order' :
return "%s %s %s" % ('Commande achat', order.getId(), order.getSourceDecisionTitle())
elif order.getPortalType() == 'Production Order' :
return "%s %s %s %ip" % ('OF', order.getId(), order.getDescription(), order.getTotalQuantity())
else :
return "%s %s" % ('Simulated Order', order.getId()) # Tried to use unicode but failed - ListBot must use unicode in % replacements
else:
LOG("Delivery Value",0,str(self.path))
delivery = o.getExplanationValue() delivery = o.getExplanationValue()
LOG("Delivery Value",0,str(delivery))
if delivery is not None: if delivery is not None:
explanation_text = "%s %s" % (delivery.getPortalType(),
delivery.getTitleOrId())
causality = delivery.getCausalityValue() causality = delivery.getCausalityValue()
if causality is None: if causality is not None:
if delivery.getPortalType() == 'Sales Packing List' : explanation_text = "%s (%s %s)" % (explanation_text,
return "%s %s %s" % ('Livraison vente', delivery.getId(), delivery.getDestinationDecisionOrganisationTitle()) causality.getPortalType(),
elif delivery.getPortalType() == 'Purchase Packing List' : causality.getTitleOrId())
return "%s %s %s" % ('Livraison achat', delivery.getId(), delivery.getSourceDecisionTitle()) return explanation_text
else :
return "%s %s" % (delivery.getPortalType(), delivery.getId())
else:
if delivery.getPortalType() == 'Sales Packing List' :
return "%s %s %s (cde %s)" % ('Livraison vente', delivery.getId(), delivery.getDestinationDecisionOrganisationTitle(), causality.getId())
elif delivery.getPortalType() == 'Purchase Packing List' :
return "%s %s %s (cde %s)" % ('Livraison achat', delivery.getId(), delivery.getSourceDecisionTitle(), causality.getId())
elif delivery.getPortalType() == 'Production Packing List' :
return "%s %s (of %s %s %ip)" % ('Livraison fabrication', delivery.getId(), causality.getId(), causality.getDescription(), causality.getTotalQuantity())
elif delivery.getPortalType() == 'Production Report' :
return "%s %s (of %s %s %ip)" % ('Rapport fabrication', delivery.getId(), causality.getId(), causality.getDescription(), causality.getTotalQuantity())
else :
return "%s %s (%s %s)" % (delivery.getPortalType(), delivery.getId(),
causality.getPortalType(), causality.getId())
return "Unknown"
class DeliveryListBrain(InventoryListBrain): class DeliveryListBrain(InventoryListBrain):
""" """
......
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