Browse Source

[FIX] Various fixs

pull/84/head
hurrinico 10 years ago
committed by eLBati
parent
commit
fb8ee276a6
  1. 10
      field_validator/ir_model_field.py
  2. 10
      field_validator/test/validator.yml

10
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.\

10
field_validator/test/validator.yml

@ -1,12 +1,8 @@
-
Try fields validator
-
!python {model: ir.model.field}: |
from nose.tools import *
!python {model: ir.model.fields}: |
from openerp.exceptions import Warning
field_ids = self.search(cr, uid, [('name', '=', 'email'), ('model', '=', 'res.partner')]
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'})
self.write(cr, uid, field_ids, {'regex_validator': r'\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b'})
Loading…
Cancel
Save