[FIX] Added sql_constraint on adding field having size<1
lp bug: https://launchpad.net/bugs/399685 fixed bzr revid: hda@hda-20090715134530-4aj0hth1olefcpdn
This commit is contained in:
parent
64ffe9c680
commit
9148c7fcdf
|
@ -229,6 +229,9 @@ class ir_model_fields(osv.osv):
|
||||||
'field_description': lambda *a: '',
|
'field_description': lambda *a: '',
|
||||||
}
|
}
|
||||||
_order = "id"
|
_order = "id"
|
||||||
|
_sql_constraints = [
|
||||||
|
('size_gt_zero', 'CHECK (size>0)', 'Size of the field can never be less than 1 !'),
|
||||||
|
]
|
||||||
def unlink(self, cr, user, ids, context=None):
|
def unlink(self, cr, user, ids, context=None):
|
||||||
for field in self.browse(cr, user, ids, context):
|
for field in self.browse(cr, user, ids, context):
|
||||||
if field.state <> 'manual':
|
if field.state <> 'manual':
|
||||||
|
@ -244,17 +247,18 @@ class ir_model_fields(osv.osv):
|
||||||
vals['model'] = model_data.model
|
vals['model'] = model_data.model
|
||||||
if context and context.get('manual',False):
|
if context and context.get('manual',False):
|
||||||
vals['state'] = 'manual'
|
vals['state'] = 'manual'
|
||||||
res = super(ir_model_fields,self).create(cr, user, vals, context)
|
res = super(ir_model_fields,self).create(cr, user, vals, context)
|
||||||
if vals.get('state','base') == 'manual':
|
if vals.get('state','base') == 'manual':
|
||||||
if not vals['name'].startswith('x_'):
|
if not vals['name'].startswith('x_'):
|
||||||
raise except_orm(_('Error'), _("Custom fields must have a name that starts with 'x_' !"))
|
raise except_orm(_('Error'), _("Custom fields must have a name that starts with 'x_' !"))
|
||||||
|
|
||||||
if 'relation' in vals and not self.pool.get('ir.model').search(cr, user, [('model','=',vals['relation'])]):
|
if 'relation' in vals and not self.pool.get('ir.model').search(cr, user, [('model','=',vals['relation'])]):
|
||||||
raise except_orm(_('Error'), _("Model %s Does not Exist !" % vals['relation']))
|
raise except_orm(_('Error'), _("Model %s Does not Exist !" % vals['relation']))
|
||||||
|
|
||||||
if self.pool.get(vals['model']):
|
if self.pool.get(vals['model']):
|
||||||
self.pool.get(vals['model']).__init__(self.pool, cr)
|
self.pool.get(vals['model']).__init__(self.pool, cr)
|
||||||
self.pool.get(vals['model'])._auto_init(cr, {})
|
self.pool.get(vals['model'])._auto_init(cr, {})
|
||||||
|
|
||||||
return res
|
return res
|
||||||
ir_model_fields()
|
ir_model_fields()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue