[IMP] Extended the field.property to new type field (char, integer, float, date, ...)
By default, when there are no multi company default, we keep the compatibility with 5.0
else we match to find the company_id for this fields.
bzr revid: christophe.chauvet@syleam.fr-20091217213828-f8edggbqnhzw41h2
This commit is contained in:
@@ -25,17 +25,6 @@ from osv import osv,fields
|
||||
# Properties
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
def _models_get2(self, cr, uid, context={}):
|
||||
obj = self.pool.get('ir.model.fields')
|
||||
ids = obj.search(cr, uid, [('view_load','=',1)])
|
||||
res = []
|
||||
done = {}
|
||||
for o in obj.browse(cr, uid, ids, context=context):
|
||||
if o.relation not in done:
|
||||
res.append( [o.relation, o.relation])
|
||||
done[o.relation] = True
|
||||
return res
|
||||
|
||||
def _models_get(self, cr, uid, context={}):
|
||||
obj = self.pool.get('ir.model.fields')
|
||||
ids = obj.search(cr, uid, [('view_load','=',1)])
|
||||
@@ -51,7 +40,7 @@ class ir_property(osv.osv):
|
||||
_name = 'ir.property'
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=128),
|
||||
'value': fields.reference('Value', selection=_models_get2, size=128),
|
||||
'value': fields.char('Value', size=128),
|
||||
'res_id': fields.reference('Resource', selection=_models_get, size=128),
|
||||
'company_id': fields.many2one('res.company', 'Company'),
|
||||
'fields_id': fields.many2one('ir.model.fields', 'Fields', ondelete='cascade', required=True)
|
||||
|
||||
+31
-22
@@ -856,9 +856,12 @@ class property(function):
|
||||
if nid:
|
||||
default_val = property.browse(cr, uid, nid[0], context).value
|
||||
|
||||
company_id = obj.pool.get('res.users').company_get(cr, uid, uid)
|
||||
company_id = obj.pool.get('res.company')._company_default_get(cr, uid, obj._name, prop, context=context)
|
||||
res = False
|
||||
newval = (id_val and obj_dest+','+str(id_val)) or False
|
||||
if val[0]:
|
||||
newval = (id_val and obj_dest+','+str(id_val)) or False
|
||||
else:
|
||||
newval = id_val or False
|
||||
if (newval != default_val) and newval:
|
||||
propdef = obj.pool.get('ir.model.fields').browse(cr, uid,
|
||||
definition_id, context=context)
|
||||
@@ -892,27 +895,33 @@ class property(function):
|
||||
for id in ids:
|
||||
res[id] = default_val
|
||||
for prop in property.browse(cr, uid, nids):
|
||||
res[int(prop.res_id.split(',')[1])] = (prop.value and \
|
||||
int(prop.value.split(',')[1])) or False
|
||||
|
||||
obj = obj.pool.get(self._obj)
|
||||
|
||||
to_check = res.values()
|
||||
if default_val and default_val not in to_check:
|
||||
to_check += [default_val]
|
||||
existing_ids = obj.search(cr, uid, [('id', 'in', to_check)])
|
||||
|
||||
for id, res_id in res.items():
|
||||
if res_id not in existing_ids:
|
||||
cr.execute('DELETE FROM ir_property WHERE value=%s', ((obj._name+','+str(res_id)),))
|
||||
res[id] = default_val
|
||||
|
||||
names = dict(obj.name_get(cr, uid, existing_ids, context))
|
||||
for r in res.keys():
|
||||
if res[r] and res[r] in names:
|
||||
res[r] = (res[r], names[res[r]])
|
||||
if prop.value.find(',') >= 0:
|
||||
res[int(prop.res_id.split(',')[1])] = (prop.value and \
|
||||
int(prop.value.split(',')[1])) or False
|
||||
else:
|
||||
res[r] = False
|
||||
res[int(prop.res_id.split(',')[1])] = prop.value or ''
|
||||
|
||||
try:
|
||||
obj = obj.pool.get(self._obj)
|
||||
|
||||
to_check = res.values()
|
||||
if default_val and default_val not in to_check:
|
||||
to_check += [default_val]
|
||||
existing_ids = obj.search(cr, uid, [('id', 'in', to_check)])
|
||||
|
||||
for id, res_id in res.items():
|
||||
if res_id not in existing_ids:
|
||||
cr.execute('DELETE FROM ir_property WHERE value=%s', ((obj._name+','+str(res_id)),))
|
||||
res[id] = default_val
|
||||
|
||||
names = dict(obj.name_get(cr, uid, existing_ids, context))
|
||||
for r in res.keys():
|
||||
if res[r] and res[r] in names:
|
||||
res[r] = (res[r], names[res[r]])
|
||||
else:
|
||||
res[r] = False
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
|
||||
def _field_get(self, cr, uid, model_name, prop):
|
||||
|
||||
Reference in New Issue
Block a user