diff --git a/field_validator/ir_model_field.py b/field_validator/ir_model_field.py index 9b53ca972..47c3a4dc1 100644 --- a/field_validator/ir_model_field.py +++ b/field_validator/ir_model_field.py @@ -25,9 +25,9 @@ import openerp from openerp import SUPERUSER_ID -class IrModelField(orm.Model): +class IrModelFields(orm.Model): - _inherit = 'ir.model.field' + _inherit = 'ir.model.fields' _columns = { 'regex_validator': fields.char( 'Validator', size=256, @@ -69,6 +69,8 @@ class IrModelField(orm.Model): def _register_hook(self, cr, ids=None): """ Wrap the methods `create` and `write` of the model """ + if ids is None: + ids = self.search(cr, SUPERUSER_ID, []) updated = False for field in self.browse(cr, SUPERUSER_ID, ids): model = field.model_id.model @@ -82,7 +84,7 @@ class IrModelField(orm.Model): return updated def create(self, cr, uid, vals, context=None): - res_id = super(IrModelField, self).create( + res_id = super(IrModelFields, self).create( cr, uid, vals, context=context) if vals.get('regex_validator'): if self._register_hook(cr, [res_id]): @@ -93,7 +95,7 @@ class IrModelField(orm.Model): def write(self, cr, uid, ids, vals, context=None): if isinstance(ids, (int, long)): ids = [ids] - super(IrModelField, self).write(cr, uid, ids, vals, context=context) + super(IrModelFields, self).write(cr, uid, ids, vals, context=context) if vals.get('regex_validator'): if self._register_hook(cr, ids): openerp.modules.registry.RegistryManager.\ diff --git a/field_validator/test/validator.yml b/field_validator/test/validator.yml index f365f9c2d..6c23bc505 100644 --- a/field_validator/test/validator.yml +++ b/field_validator/test/validator.yml @@ -1,12 +1,8 @@ - - Try fields validator + Try fields validator - - !python {model: ir.model.field}: | - from nose.tools import * - from openerp.exceptions import Warning - field_ids = self.search(cr, uid, [('name', '=', 'email'), ('model', '=', 'res.partner')] - assert len(field_ids) == 1, 'There must be 1 email field' - self.write(cr, uid, field_ids, {'regex_validator': r'\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b'} - partner_id = self.pool.get('res.partner').create(cr, uid, {'name': 'test_partner'}) - with assert_raises(Error): - self.pool.get('res.partner').write(cr, uid, partner_id, {'email': 'jhon'}) + !python {model: ir.model.fields}: | + from openerp.exceptions import Warning + field_ids = self.search(cr, uid, [('name', '=', 'email'), ('model', '=', 'res.partner')]) + assert len(field_ids) == 1, 'There must be 1 email field' + self.write(cr, uid, field_ids, {'regex_validator': r'\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b'})