Commit 580bbeb2 authored by Nicolas Dumazet's avatar Nicolas Dumazet

Be less scary on misconfigurations: warn instead of printing tracebacks


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32203 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 30ce4f80
......@@ -25,6 +25,8 @@
#
##############################################################################
from zLOG import LOG, WARNING
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import PropertySheet
......@@ -167,21 +169,32 @@ class Measure(XMLMatrix):
Returns the list of rows to insert in the measure table of the catalog.
Called by Resource.getMeasureRowList.
"""
quantity_unit = self.getQuantityUnitValue()
quantity_unit_value = self.getQuantityUnitValue()
metric_type = self.getMetricType()
if quantity_unit is None or not metric_type or \
quantity_unit.getParentId() != metric_type.split('/', 1)[0]:
if quantity_unit_value is None or not metric_type or \
quantity_unit_value.getParentId() != metric_type.split('/', 1)[0]:
return ()
quantity_unit_uid = quantity_unit.getUid()
def getQuantity(quantity_unit_value):
quantity_unit_uid = quantity_unit_value.getUid()
try:
return quantity_unit_definition_dict[quantity_unit_uid][1]
except KeyError:
LOG("Measure", WARNING,
"could not find an Unit Definition for '%s' while " \
"indexing Measure '%s'" % \
(quantity_unit_value.getRelativeUrl(),
self.getRelativeUrl()))
return None
uid = self.getUid()
resource = self.getResourceValue()
resource_uid = resource.getUid()
metric_type_uid = self.getMetricTypeUid()
quantity = self.getQuantity()
try:
quantity_unit = quantity_unit_definition_dict[quantity_unit_uid][1]
except KeyError:
quantity_unit = getQuantity(quantity_unit_value)
if quantity_unit is None:
return ()
# The only purpose of the defining a default measure explicitly is to
......@@ -198,11 +211,11 @@ class Measure(XMLMatrix):
# so we simply return 1 row.
if quantity is not None:
quantity *= quantity_unit
management_unit_uid = resource.getQuantityUnitUid()
management_unit_value = resource.getQuantityUnitValue()
management_unit_quantity = None
if management_unit_uid is not None:
management_unit_quantity = quantity_unit_definition_dict\
[management_unit_uid][1]
if management_unit_value is not None:
management_unit_quantity = getQuantity(management_unit_value)
if (not default or quantity == management_unit_quantity):
return (uid, resource_uid, '^', metric_type_uid, quantity),
return ()
......
......@@ -877,11 +877,21 @@ class Resource(XMLMatrix, Variated):
if definition_group.getValidationState() != "validated":
continue
standard_quantity_unit_uid = definition_group.getQuantityUnitUid()
if standard_quantity_unit_uid is None:
standard_quantity_unit_value = definition_group.getQuantityUnitValue()
if standard_quantity_unit_value is None:
continue
uid = standard_quantity_unit_value.getUid()
try:
reference_ratio = global_definition_dict[uid][1]
except KeyError:
LOG("Resource", WARNING,
"could not find a global Unit Definition for '%s' while " \
"indexing local Definition Group '%s'" % \
(standard_quantity_unit_value.getRelativeUrl(),
definition_group.getRelativeUrl()))
continue
reference_ratio = global_definition_dict[standard_quantity_unit_uid][1]
for definition in definition_group.objectValues(portal_type= \
'Quantity Unit Conversion Definition'):
if definition.getValidationState() != "validated":
......@@ -957,7 +967,15 @@ class Resource(XMLMatrix, Variated):
# a row for the management unit, with the resource's uid as uid, and
# a generic metric_type.
quantity_unit_uid = quantity_unit_value.getUid()
quantity = quantity_unit_definition_dict[quantity_unit_uid][1]
try:
quantity = quantity_unit_definition_dict[quantity_unit_uid][1]
except KeyError:
LOG("Resource", WARNING,
"could not find an Unit Definition for '%s' while " \
"indexing Resource '%s'" % \
(quantity_unit_value.getRelativeUrl(),
self.getRelativeUrl()))
quantity = None
metric_type_uid = self.getPortalObject().portal_categories \
.getCategoryUid(metric_type, 'metric_type')
......
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