improvement in ir.model.fields for view and model

* check the existance of the relational model

bzr revid: mga@tinyerp.com-20090417091930-fos208yk5teh420p
This commit is contained in:
Mantavya Gajjar 2009-04-17 14:49:30 +05:30
parent 7f8550c59e
commit 41249e7b8c
2 changed files with 10 additions and 7 deletions

View File

@ -750,10 +750,8 @@
<group colspan="2" col="2">
<separator string="Field Type" colspan="2"/>
<field name="ttype" select="2"/>
<field name="relation" attrs="{'required': [('ttype','in',['many2one','one2many','many2many'])],
'readonly': [('ttype','!=','one2many'), ('ttype','!=','many2one'), ('ttype','!=','many2many')]}"/>
<field name="relation_field" attrs="{'required': [('ttype','=','one2many')],
'readonly': [('ttype','!=','one2many')]}"/>
<field name="relation" attrs="{'required': [('ttype','in',['many2one','one2many','many2many'])],'readonly': [('ttype','!=','one2many'), ('ttype','!=','many2one'), ('ttype','!=','many2many')]}"/>
<field name="relation_field" attrs="{'required': [('ttype','=','one2many')], 'readonly': [('ttype','!=','one2many')]}"/>
<field name="selection" attrs="{'required': [('ttype','in',['selection','reference'])], 'readonly': [('ttype','not in',['selection','reference'])]}"/>
<field name="size" attrs="{'required': [('ttype','in',['char','reference'])], 'readonly': [('ttype','not in',['char','reference'])]}"/>
<field name="state"/>

View File

@ -243,9 +243,14 @@ class ir_model_fields(osv.osv):
if vals.get('state','base') == 'manual':
if not vals['name'].startswith('x_'):
raise except_orm(_('Error'), _("Custom fields must have a name that starts with 'x_' !"))
if self.pool.get(vals['model']):
self.pool.get(vals['model']).__init__(self.pool, cr)
self.pool.get(vals['model'])._auto_init(cr, {})
model_ids = self.pool.get('ir.model').search(cr, user, [('model','=',vals['relation'])])
if model_ids:
if self.pool.get(vals['model']):
self.pool.get(vals['model']).__init__(self.pool, cr)
self.pool.get(vals['model'])._auto_init(cr, {})
else:
raise except_orm(_('Error'), _("Model %s Does not Exist !" % vals['relation']))
return res
ir_model_fields()