From c3ec58b1a40cdf8f1b0606f650200defcc540451 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Sat, 18 Sep 2010 16:35:59 +0200 Subject: [PATCH] improve_speed bzr revid: fp@tinyerp.com-20100918143559-hcgi2x1af0pyt1ph --- bin/addons/base/res/ir_property.py | 2 +- bin/osv/fields.py | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/bin/addons/base/res/ir_property.py b/bin/addons/base/res/ir_property.py index 78c5f6c6639..c49c69816b2 100644 --- a/bin/addons/base/res/ir_property.py +++ b/bin/addons/base/res/ir_property.py @@ -147,7 +147,7 @@ class ir_property(osv.osv): elif record.type == 'binary': return record.value_binary elif record.type == 'many2one': - return record.value_reference.id + return record.value_reference elif record.type == 'datetime': return record.value_datetime elif record.type == 'date': diff --git a/bin/osv/fields.py b/bin/osv/fields.py index e368406b756..1d39ff8b673 100644 --- a/bin/osv/fields.py +++ b/bin/osv/fields.py @@ -895,7 +895,7 @@ class property(function): for prop_rec in prop.browse(cr, uid, ids, context=context): if prop_rec.fields_id.name in default_value: continue - default_value[prop_rec.fields_id.name] = prop.get_by_record(cr, uid, prop_rec, context=context) + default_value[prop_rec.fields_id.name] = prop.get_by_record(cr, uid, prop_rec, context=context) or False return default_value def _get_by_id(self, obj, cr, uid, prop_name, ids, context=None): @@ -910,6 +910,7 @@ class property(function): return [] + # TODO: to rewrite more clean def _fnct_write(self, obj, cr, uid, id, prop_name, id_val, obj_dest, context=None): if context is None: context = {} @@ -950,9 +951,24 @@ class property(function): for id in ids: res[id] = default_val.copy() - for prop in properties.browse(cr, uid, nids, context=context): + replaces = {} + brs = properties.browse(cr, uid, nids, context=context) + for prop in brs: value = properties.get_by_record(cr, uid, prop, context=context) res[prop.res_id.id][prop.fields_id.name] = value or False + if value: + replaces.setdefault(value._name, {}) + replaces[value._name][value.id] = True + + for rep in replaces: + replaces[rep] = dict(obj.pool.get(rep).name_get(cr, uid, replaces[rep].keys(), context=context)) + + for prop in brs: + if prop.type == 'many2one': + for id in ids: + if res[id][prop.fields_id.name]: + res[id][prop.fields_id.name] = replaces[res[id][prop.fields_id.name]._name].get(res[id][prop.fields_id.name], False) + return res