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