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