merge with main trunk
bzr revid: hda@tinyerp.com-20100505141447-wicg8n72j309gjs2
This commit is contained in:
commit
07bd48700b
|
@ -22,7 +22,7 @@
|
|||
|
||||
{
|
||||
'name': 'Base',
|
||||
'version': '1.1',
|
||||
'version': '1.2',
|
||||
'category': 'Generic Modules/Base',
|
||||
'description': """The kernel of OpenERP, needed for all installation.""",
|
||||
'author': 'Tiny',
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
<form string="Users">
|
||||
<notebook colspan="4">
|
||||
<page string="Current Activity">
|
||||
<field name="company_id" widget="selection" readonly="0" context="{'user_prefence':True}"/>
|
||||
<field name="company_id" widget="selection" readonly="0" context="{'user_preference':True}"/>
|
||||
<newline/>
|
||||
<separator colspan="4" string="Preferences"/>
|
||||
</page>
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf8 -*-
|
||||
|
||||
__name__ = "ir.property: Rename column value to value_reference"
|
||||
|
||||
def migrate(cr, version):
|
||||
rename_column(cr, 'ir_property', 'value', 'value_reference')
|
||||
|
||||
def column_exists(cr, table, column):
|
||||
cr.execute("SELECT count(1)"
|
||||
" FROM pg_class c, pg_attribute a"
|
||||
" WHERE c.relname=%s"
|
||||
" AND c.oid=a.attrelid"
|
||||
" AND a.attname=%s",
|
||||
(table, column))
|
||||
return cr.fetchone()[0] != 0
|
||||
|
||||
def rename_column(cr, table, old, new):
|
||||
if column_exists(cr, table, old) and not column_exists(cr, table, new):
|
||||
cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO "%s"' % (table, old, new))
|
||||
|
|
@ -20,47 +20,159 @@
|
|||
##############################################################################
|
||||
|
||||
from osv import osv,fields
|
||||
|
||||
from operator import attrgetter
|
||||
import time
|
||||
# -------------------------------------------------------------------------
|
||||
# Properties
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
def _models_get(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.model_id.id not in done:
|
||||
res.append( [o.model_id.model, o.model_id.name])
|
||||
done[o.model_id.id] = True
|
||||
return res
|
||||
|
||||
class ir_property(osv.osv):
|
||||
_name = 'ir.property'
|
||||
_columns = {
|
||||
'name': fields.char('Name', 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)
|
||||
}
|
||||
def unlink(self, cr, uid, ids, context={}):
|
||||
if ids:
|
||||
cr.execute('DELETE FROM ir_model_fields WHERE id IN (SELECT fields_id FROM ir_property WHERE (fields_id IS NOT NULL) AND (id = ANY (%s)))', (ids,))
|
||||
res = super(ir_property, self).unlink(cr, uid, ids, context)
|
||||
|
||||
def _models_field_get(self, cr, uid, field_key, field_value, context=None):
|
||||
get = attrgetter(field_key, field_value)
|
||||
|
||||
obj = self.pool.get('ir.model.fields')
|
||||
ids = obj.search(cr, uid, [('view_load','=',1)], context=context)
|
||||
res = set()
|
||||
for o in obj.browse(cr, uid, ids, context=context):
|
||||
res.add(get(o))
|
||||
return res
|
||||
|
||||
def get(self, cr, uid, name, model, res_id=False, context={}):
|
||||
cr.execute('select id from ir_model_fields where name=%s and model=%s', (name, model))
|
||||
res = cr.fetchone()
|
||||
if res:
|
||||
ucid = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
|
||||
nid = self.search(cr, uid, [('fields_id','=',res[0]),('res_id','=',res_id),('company_id','=',ucid)])
|
||||
if nid:
|
||||
d = self.browse(cr, uid, nid[0], context).value
|
||||
return (d and int(d.split(',')[1])) or False
|
||||
def _models_get(self, cr, uid, context=None):
|
||||
return self._models_field_get(cr, uid, 'model_id.model', 'model_id.name',
|
||||
context)
|
||||
|
||||
def _models_get2(self, cr, uid, context=None):
|
||||
return self._models_field_get(cr, uid, 'relation', 'relation', context)
|
||||
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=128),
|
||||
|
||||
'res_id': fields.reference('Resource', selection=_models_get, size=128,
|
||||
help="If not set, act as default property"),
|
||||
'company_id': fields.many2one('res.company', 'Company'),
|
||||
'fields_id': fields.many2one('ir.model.fields', 'Fields', ondelete='cascade', required=True),
|
||||
|
||||
'value_float' : fields.float('Value'),
|
||||
'value_integer' : fields.integer_big('Value'), # will contain (int, bigint)
|
||||
'value_text' : fields.text('Value'), # will contain (char, text)
|
||||
'value_binary' : fields.binary('Value'),
|
||||
'value_reference': fields.reference('Value', selection=_models_get2, size=128),
|
||||
'value_datetime' : fields.datetime('Value'),
|
||||
|
||||
'type' : fields.selection([('char', 'Char'),
|
||||
('float', 'Float'),
|
||||
('integer', 'Integer'),
|
||||
('integer_big', 'Integer Big'),
|
||||
('text', 'Text'),
|
||||
('binary', 'Binary'),
|
||||
('many2one', 'Many2One'),
|
||||
('date', 'Date'),
|
||||
('datetime', 'DateTime'),
|
||||
],
|
||||
'Type',
|
||||
required=True,
|
||||
select=1),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'type': 'many2one',
|
||||
}
|
||||
|
||||
def _update_values(self, cr, uid, ids, values):
|
||||
value = values.pop('value', None)
|
||||
if not value:
|
||||
return values
|
||||
type_ = values.get('type', 'many2one')
|
||||
type2field = {
|
||||
'char': 'value_text',
|
||||
'float': 'value_float',
|
||||
'integer': 'value_integer',
|
||||
'integer_big': 'value_integer',
|
||||
'text': 'value_text',
|
||||
'binary': 'value_binary',
|
||||
'many2one': 'value_reference',
|
||||
'date' : 'value_datetime',
|
||||
'datetime' : 'value_datetime',
|
||||
}
|
||||
field = type2field.get(type_)
|
||||
if not field:
|
||||
raise osv.except_osv('Error', 'Invalid type')
|
||||
|
||||
if field == 'value_reference':
|
||||
if isinstance(value, osv.orm.browse_record):
|
||||
value = '%s,%d' % (value._name, value.id)
|
||||
elif isinstance(value, (int, long)):
|
||||
field_id = values.get('fields_id')
|
||||
if not field_id:
|
||||
if not ids:
|
||||
raise ValueError()
|
||||
field_id = self.browse(cr, uid, ids[0]).fields_id
|
||||
else:
|
||||
field_id = self.pool.get('ir.model.fields').browse(cr, uid, field_id)
|
||||
|
||||
value = '%s,%d' % (field_id.relation, value)
|
||||
|
||||
values[field] = value
|
||||
return values
|
||||
|
||||
|
||||
def write(self, cr, uid, ids, values, context=None):
|
||||
return super(ir_property, self).write(cr, uid, ids, self._update_values(cr, uid, ids, values), context=context)
|
||||
|
||||
def create(self, cr, uid, values, context=None):
|
||||
return super(ir_property, self).create(cr, uid, self._update_values(cr, uid, None, values), context=context)
|
||||
|
||||
def get_by_id(self, cr, uid, record_ids, context=None):
|
||||
if isinstance(record_ids, (int, long)):
|
||||
record_ids = [record_ids]
|
||||
|
||||
if not record_ids:
|
||||
return False
|
||||
|
||||
record = self.browse(cr, uid, record_ids[0], context=context)
|
||||
|
||||
if record.type in ('char', 'text'):
|
||||
return record.value_text
|
||||
elif record.type == 'float':
|
||||
return record.value_float
|
||||
elif record.type in ('integer', 'integer_big'):
|
||||
return record.value_integer
|
||||
elif record.type == 'binary':
|
||||
return record.value_binary
|
||||
elif record.type == 'many2one':
|
||||
return record.value_reference
|
||||
elif record.type == 'datetime':
|
||||
return record.value_datetime
|
||||
elif record.type == 'date':
|
||||
return time.strftime('%Y-%m-%d', time.strptime(record.value_datetime, '%Y-%m-%d %H:%M:%S'))
|
||||
|
||||
return False
|
||||
|
||||
def get(self, cr, uid, name, model, res_id=False, context=None):
|
||||
domain = self._get_domain(cr, uid, name, model, context=context)
|
||||
if domain is not None:
|
||||
domain = [('res_id', '=', res_id)] + domain
|
||||
nid = self.search(cr, uid, domain, context=context)
|
||||
return self.get_by_id(cr, uid, nid, context=context)
|
||||
return False
|
||||
|
||||
def _get_domain(self, cr, uid, prop_name, model, context=None):
|
||||
cr.execute('select id from ir_model_fields where name=%s and model=%s', (prop_name, model))
|
||||
res = cr.fetchone()
|
||||
if not res:
|
||||
return None
|
||||
|
||||
company = self.pool.get('res.company')
|
||||
cid = company._company_default_get(cr, uid, model, res[0],
|
||||
context=context)
|
||||
|
||||
domain = ['&', ('fields_id', '=', res[0]),
|
||||
'|', ('company_id', '=', cid), ('company_id', '=', False)]
|
||||
return domain
|
||||
|
||||
ir_property()
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,25 @@
|
|||
<field name="name" select="1"/>
|
||||
<field name="company_id" select="1" groups="base.group_multi_company"/>
|
||||
<field colspan="4" name="fields_id" select="1"/>
|
||||
<field colspan="4" name="value"/>
|
||||
<field colspan="4" name="type"/>
|
||||
<group colspan="4" attrs="{'invisible' : [('type', 'not in', ('integer', 'integer_big'))]}">
|
||||
<field colspan="4" name="value_integer" widget="integer"/>
|
||||
</group>
|
||||
<group colspan="4" attrs="{'invisible' : [('type', '!=', 'float')]}">
|
||||
<field colspan="4" name="value_float" />
|
||||
</group>
|
||||
<group colspan="4" attrs="{'invisible' : [('type', 'not in', ('date', 'datetime'))]}">
|
||||
<field colspan="4" name="value_datetime" />
|
||||
</group>
|
||||
<group colspan="4" attrs="{'invisible' : [('type', 'not in', ('char', 'text'))]}">
|
||||
<field colspan="4" name="value_text" />
|
||||
</group>
|
||||
<group colspan="4" attrs="{'invisible' : [('type', '!=', 'many2one')]}">
|
||||
<field colspan="4" name="value_reference" />
|
||||
</group>
|
||||
<group colspan="4" attrs="{'invisible' : [('type', '!=', 'binary')]}">
|
||||
<field colspan="4" name="value_binary" />
|
||||
</group>
|
||||
<field colspan="4" name="res_id" groups="base.group_extended"/>
|
||||
</form>
|
||||
</field>
|
||||
|
|
|
@ -88,14 +88,16 @@ class res_company(osv.osv):
|
|||
'user_ids': fields.many2many('res.users', 'res_company_users_rel', 'cid', 'user_id', 'Accepted Users')
|
||||
}
|
||||
|
||||
def search(self, cr, user, args, offset=0, limit=None, order=None,
|
||||
def search(self, cr, uid, args, offset=0, limit=None, order=None,
|
||||
context=None, count=False):
|
||||
if context and context.has_key('user_prefence') and context['user_prefence']:
|
||||
cmp_ids = []
|
||||
data_user = self.pool.get('res.users').browse(cr, user, [user], context=context)
|
||||
map(lambda x: cmp_ids.append(x.id), data_user[0].company_ids)
|
||||
return [data_user[0].company_id.id] + cmp_ids
|
||||
return super(res_company, self).search(cr, user, args, offset=offset, limit=limit, order=order,
|
||||
|
||||
user_preference = context and context.get('user_preference', False) or False
|
||||
if user_preference:
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||
cmp_ids = list(set([user.company_id.id] + [cmp.id for cmp in user.company_ids]))
|
||||
|
||||
return cmp_ids
|
||||
return super(res_company, self).search(cr, uid, args, offset=offset, limit=limit, order=order,
|
||||
context=context, count=count)
|
||||
|
||||
def _company_default_get(self, cr, uid, object=False, field=False, context=None):
|
||||
|
@ -107,11 +109,9 @@ class res_company(osv.osv):
|
|||
proxy = self.pool.get('multi_company.default')
|
||||
args = [
|
||||
('object_id.model', '=', object),
|
||||
('field_id', '=', field),
|
||||
]
|
||||
if field:
|
||||
args.append(('field_id.name','=',field))
|
||||
else:
|
||||
args.append(('field_id','=',False))
|
||||
|
||||
ids = proxy.search(cr, uid, args, context=context)
|
||||
for rule in proxy.browse(cr, uid, ids, context):
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
|
|
|
@ -873,87 +873,84 @@ class serialized(_column):
|
|||
|
||||
class property(function):
|
||||
|
||||
def _fnct_write(self, obj, cr, uid, id, prop, id_val, val, context=None):
|
||||
if not context:
|
||||
context = {}
|
||||
(obj_dest,) = val
|
||||
definition_id = self._field_get(cr, uid, obj._name, prop)
|
||||
def _get_default(self, obj, cr, uid, prop_name, context=None):
|
||||
prop = obj.pool.get('ir.property')
|
||||
domain = prop._get_domain(cr, uid, prop_name, obj._name, context)
|
||||
ids = prop.search(cr, uid, domain, order='company_id', context=context)
|
||||
if not ids:
|
||||
return False
|
||||
return prop.get_by_id(cr, uid, ids, context=context)
|
||||
|
||||
property = obj.pool.get('ir.property')
|
||||
nid = property.search(cr, uid, [('fields_id', '=', definition_id),
|
||||
('res_id', '=', obj._name+','+str(id))])
|
||||
while len(nid):
|
||||
cr.execute('DELETE FROM ir_property WHERE id=%s', (nid.pop(),))
|
||||
def _get_by_id(self, obj, cr, uid, prop_name, ids, context=None):
|
||||
prop = obj.pool.get('ir.property')
|
||||
vids = [obj._name + ',' + str(oid) for oid in ids]
|
||||
|
||||
nid = property.search(cr, uid, [('fields_id', '=', definition_id),
|
||||
('res_id', '=', False)])
|
||||
default_val = False
|
||||
if nid:
|
||||
default_val = property.browse(cr, uid, nid[0], context).value
|
||||
|
||||
company_id = obj.pool.get('res.company')._company_default_get(cr, uid, obj._name, prop, context=context)
|
||||
res = False
|
||||
if val[0]:
|
||||
newval = (id_val and obj_dest+','+str(id_val)) or False
|
||||
domain = prop._get_domain(cr, uid, prop_name, obj._name, context)
|
||||
if domain is not None:
|
||||
domain = [('res_id', 'in', vids)] + domain
|
||||
return prop.search(cr, uid, domain, context=context)
|
||||
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)
|
||||
res = property.create(cr, uid, {
|
||||
'name': propdef.name,
|
||||
'value': newval,
|
||||
'res_id': obj._name+','+str(id),
|
||||
'company_id': company_id,
|
||||
'fields_id': definition_id
|
||||
}, context=context)
|
||||
return res
|
||||
return []
|
||||
|
||||
def _fnct_read(self, obj, cr, uid, ids, prop, val, context=None):
|
||||
if not context:
|
||||
|
||||
def _fnct_write(self, obj, cr, uid, id, prop_name, id_val, obj_dest, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
nids = self._get_by_id(obj, cr, uid, prop_name, [id], context)
|
||||
if nids:
|
||||
cr.execute('DELETE FROM ir_property WHERE id IN %s', (tuple(nids),))
|
||||
|
||||
default_val = self._get_default(obj, cr, uid, prop_name, context)
|
||||
|
||||
if id_val and id_val != default_val:
|
||||
def_id = self._field_get(cr, uid, obj._name, prop_name)
|
||||
company = obj.pool.get('res.company')
|
||||
cid = company._company_default_get(cr, uid, obj._name, def_id,
|
||||
context=context)
|
||||
propdef = obj.pool.get('ir.model.fields').browse(cr, uid, def_id,
|
||||
context=context)
|
||||
prop = obj.pool.get('ir.property')
|
||||
return prop.create(cr, uid, {
|
||||
'name': propdef.name,
|
||||
'value': id_val,
|
||||
'res_id': obj._name+','+str(id),
|
||||
'company_id': cid,
|
||||
'fields_id': def_id,
|
||||
'type': self._type,
|
||||
}, context=context)
|
||||
return False
|
||||
|
||||
|
||||
def _fnct_read(self, obj, cr, uid, ids, prop_name, obj_dest, context=None):
|
||||
from orm import browse_record
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
property = obj.pool.get('ir.property')
|
||||
definition_id = self._field_get(cr, uid, obj._name, prop)
|
||||
|
||||
nid = property.search(cr, uid, [('fields_id', '=', definition_id),
|
||||
('res_id', '=', False)])
|
||||
default_val = False
|
||||
if nid:
|
||||
d = property.browse(cr, uid, nid[0], context).value
|
||||
default_val = (d and int(d.split(',')[1])) or False
|
||||
default_val = self._get_default(obj, cr, uid, prop_name, context)
|
||||
if isinstance(default_val, browse_record):
|
||||
default_val = default_val.id
|
||||
else:
|
||||
default_val = False
|
||||
|
||||
vids = [obj._name + ',' + str(id) for id in ids]
|
||||
nids = property.search(cr, uid, [('fields_id', '=', definition_id),
|
||||
('res_id', 'in', vids)])
|
||||
nids = self._get_by_id(obj, cr, uid, prop_name, ids, context)
|
||||
|
||||
res = {}
|
||||
for id in ids:
|
||||
res[id] = default_val
|
||||
for prop in property.browse(cr, uid, nids):
|
||||
if prop.value.find(',') >= 0:
|
||||
res[int(prop.res_id.id)] = (prop.value and \
|
||||
int(prop.value.split(',')[1])) or False
|
||||
else:
|
||||
res[int(prop.res_id.id)] = prop.value or ''
|
||||
|
||||
if self._obj:
|
||||
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
|
||||
value = prop.get_by_id(context=context)
|
||||
if isinstance(value, browse_record):
|
||||
if not value.exists():
|
||||
cr.execute('DELETE FROM ir_property WHERE id=%s', (prop.id,))
|
||||
continue
|
||||
value = value.id
|
||||
res[prop.res_id.id] = value or False
|
||||
return res
|
||||
|
||||
|
||||
def _field_get(self, cr, uid, model_name, prop):
|
||||
if not self.field_id.get(cr.dbname):
|
||||
cr.execute('SELECT id \
|
||||
|
@ -964,9 +961,10 @@ class property(function):
|
|||
return self.field_id[cr.dbname]
|
||||
|
||||
def __init__(self, obj_prop, **args):
|
||||
# TODO remove obj_prop parameter (use many2one type)
|
||||
self.field_id = {}
|
||||
function.__init__(self, self._fnct_read, False, self._fnct_write,
|
||||
(obj_prop, ), **args)
|
||||
obj_prop, **args)
|
||||
|
||||
def restart(self):
|
||||
self.field_id = {}
|
||||
|
|
|
@ -170,6 +170,7 @@ class browse_record(object):
|
|||
def __getitem__(self, name):
|
||||
if name == 'id':
|
||||
return self._id
|
||||
|
||||
if name not in self._data[self._id]:
|
||||
# build the list of fields we will fetch
|
||||
|
||||
|
@ -179,10 +180,12 @@ class browse_record(object):
|
|||
elif name in self._table._inherit_fields:
|
||||
col = self._table._inherit_fields[name][2]
|
||||
elif hasattr(self._table, str(name)):
|
||||
if isinstance(getattr(self._table, name), (types.MethodType, types.LambdaType, types.FunctionType)):
|
||||
return lambda *args, **argv: getattr(self._table, name)(self._cr, self._uid, [self._id], *args, **argv)
|
||||
attr = getattr(self._table, name)
|
||||
|
||||
if isinstance(attr, (types.MethodType, types.LambdaType, types.FunctionType)):
|
||||
return lambda *args, **argv: attr(self._cr, self._uid, [self._id], *args, **argv)
|
||||
else:
|
||||
return getattr(self._table, name)
|
||||
return attr
|
||||
else:
|
||||
self.logger.notifyChannel("browse_record", netsvc.LOG_WARNING,
|
||||
"Field '%s' does not exist in object '%s': \n%s" % (
|
||||
|
@ -250,6 +253,8 @@ class browse_record(object):
|
|||
context=self._context,
|
||||
list_class=self._list_class,
|
||||
fields_process=self._fields_process)
|
||||
else:
|
||||
new_data[n] = ids2
|
||||
else:
|
||||
new_data[n] = browse_null()
|
||||
else:
|
||||
|
@ -271,6 +276,7 @@ class browse_record(object):
|
|||
else:
|
||||
new_data[n] = data[n]
|
||||
self._data[data['id']].update(new_data)
|
||||
|
||||
if not name in self._data[self._id]:
|
||||
#how did this happen?
|
||||
self.logger.notifyChannel("browse_record", netsvc.LOG_ERROR,
|
||||
|
@ -299,9 +305,13 @@ class browse_record(object):
|
|||
return "browse_record(%s, %d)" % (self._table_name, self._id)
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, browse_record):
|
||||
return False
|
||||
return (self._table_name, self._id) == (other._table_name, other._id)
|
||||
|
||||
def __ne__(self, other):
|
||||
if not isinstance(other, browse_record):
|
||||
return True
|
||||
return (self._table_name, self._id) != (other._table_name, other._id)
|
||||
|
||||
# we need to define __unicode__ even though we've already defined __str__
|
||||
|
@ -2577,14 +2587,14 @@ class orm(orm_template):
|
|||
or False
|
||||
if isinstance(fld_def, fields.property):
|
||||
property_obj = self.pool.get('ir.property')
|
||||
definition_id = fld_def._field_get(cr, uid, self._name, f)
|
||||
nid = property_obj.search(cr, uid, [('fields_id', '=',
|
||||
definition_id), ('res_id', '=', False)])
|
||||
if nid:
|
||||
prop_value = property_obj.browse(cr, uid, nid[0],
|
||||
context=context).value
|
||||
value[f] = (prop_value and int(prop_value.split(',')[1])) \
|
||||
or False
|
||||
prop_value = property_obj.get(cr, uid, f, self._name, context=context)
|
||||
if prop_value:
|
||||
if isinstance(prop_value, (browse_record, browse_null)):
|
||||
value[f] = prop_value.id
|
||||
else:
|
||||
value[f] = prop_value
|
||||
else:
|
||||
value[f] = False
|
||||
|
||||
# get the default values set by the user and override the default
|
||||
# values defined in the object
|
||||
|
@ -2976,7 +2986,7 @@ class orm(orm_template):
|
|||
|
||||
properties = self.pool.get('ir.property')
|
||||
domain = [('res_id', '=', False),
|
||||
('value', 'in', ['%s,%s' % (self._name, i) for i in ids]),
|
||||
('value_reference', 'in', ['%s,%s' % (self._name, i) for i in ids]),
|
||||
]
|
||||
if properties.search(cr, uid, domain, context=context):
|
||||
raise except_orm(_('Error'), _('Unable to delete this document because it is used as a default property'))
|
||||
|
@ -3802,9 +3812,12 @@ class orm(orm_template):
|
|||
trans_obj.create(cr, uid, record, context)
|
||||
return new_id
|
||||
|
||||
def exists(self, cr, uid, id, context=None):
|
||||
cr.execute('SELECT count(1) FROM "%s" where id=%%s' % (self._table,), (id,))
|
||||
return bool(cr.fetchone()[0])
|
||||
def exists(self, cr, uid, ids, context=None):
|
||||
if type(ids) in (int,long):
|
||||
ids = [ids]
|
||||
query = 'SELECT count(1) FROM "%s"' % (self._table)
|
||||
cr.execute(query + "WHERE ID IN %s", (tuple(ids),))
|
||||
return cr.fetchone()[0] == len(ids)
|
||||
|
||||
def check_recursion(self, cr, uid, ids, parent=None):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue