Commit 551230ef authored by Nicolas Dumazet's avatar Nicolas Dumazet

no need to compare during each loop step the value of default measure:

Since both getMeasureRowList and getDefaultMeasure use the same getMeasureList,
if getDefaultMeasure returns a non-None measure, we _know_ that we will go
through that value in getMeasureRowList.
getDefaultMeasure == None <=> management_unit has to be inserted.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30414 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7daf8995
......@@ -865,10 +865,6 @@ class Resource(XMLMatrix, Variated):
if quantity_unit_value is None:
return ()
quantity_unit = quantity_unit_value.getCategoryRelativeUrl()
default = self.getDefaultMeasure(quantity_unit)
if default is not None:
default = default.getRelativeUrl()
metric_type_map = {} # duplicate metric_type are not valid
for measure in self.getMeasureList():
......@@ -877,24 +873,24 @@ class Resource(XMLMatrix, Variated):
metric_type_map[metric_type] = None
else:
metric_type_map[metric_type] = measure
if measure.getRelativeUrl() == default:
quantity_unit = ''
insert_list = []
for measure in metric_type_map.itervalues():
if measure is not None:
insert_list += measure.asCatalogRowList()
metric_type = quantity_unit.split('/', 1)[0]
if metric_type and metric_type not in metric_type_map:
# At this point, we know there is no default measure and we must add
# a row for the management unit, with the resource's uid as uid, and
# a generic metric_type.
quantity = quantity_unit_value.getProperty('quantity')
metric_type_uid = self.getPortalObject().portal_categories \
.getCategoryUid(metric_type, 'metric_type')
if quantity and metric_type_uid:
uid = self.getUid()
insert_list += (uid, uid, '^', metric_type_uid, float(quantity)),
quantity_unit = quantity_unit_value.getCategoryRelativeUrl()
if self.getDefaultMeasure(quantity_unit) is None:
metric_type = quantity_unit.split('/', 1)[0]
if metric_type and metric_type not in metric_type_map:
# At this point, we know there is no default measure and we must add
# a row for the management unit, with the resource's uid as uid, and
# a generic metric_type.
quantity = quantity_unit_value.getProperty('quantity')
metric_type_uid = self.getPortalObject().portal_categories \
.getCategoryUid(metric_type, 'metric_type')
if quantity and metric_type_uid:
uid = self.getUid()
insert_list += (uid, uid, '^', metric_type_uid, float(quantity)),
return insert_list
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