← Back to team overview

openerp-dev-web team mailing list archive

lp:~openerp-dev/openobject-server/6.0-opw-fields_name_constraint_-ach into lp:openobject-server/6.0

 

Anup(OpenERP) has proposed merging lp:~openerp-dev/openobject-server/6.0-opw-fields_name_constraint_-ach into lp:openobject-server/6.0.

Requested reviews:
  Olivier Dony (OpenERP) (odo)
  Jay Vora (OpenERP) (jvo-openerp)
  xrg (xrg)
  Christophe (OpenERP) (kangol)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/6.0-opw-fields_name_constraint_-ach/+merge/53967

Hello,


    Now the Constraint restricts the following,

1. Custom field name must start with 'x_'.
2. All field name must not contain special characters or white spaces.
3. All field name must be in lowercase.
4. All the fieldname must start with either alphabets or '_' and not digits.


Your views please.
Thanks.
-- 
https://code.launchpad.net/~openerp-dev/openobject-server/6.0-opw-fields_name_constraint_-ach/+merge/53967
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-server/6.0-opw-fields_name_constraint_-ach.
=== modified file 'bin/addons/base/ir/ir_model.py'
--- bin/addons/base/ir/ir_model.py	2011-01-20 16:27:06 +0000
+++ bin/addons/base/ir/ir_model.py	2011-03-18 10:02:25 +0000
@@ -220,6 +220,20 @@
     }
     _order = "name"
 
+
+    def _check_field_name(self, cr, uid, ids, context=None):
+        for field in self.browse(cr, uid, ids, context=context):
+            if field.state=='manual':
+                if not field.name.startswith('x_'):
+                    return False
+            if not re.match('^[a-z_][a-z_0-9]+$',field.name):
+                return False
+        return True
+
+    _constraints = [
+        (_check_field_name, _('The Field name must start with x_ and not contain any special character !'), ['name']),
+    ]
+    
     def _check_selection(self, cr, uid, selection, context=None):
         try:
             selection_list = eval(selection)


Follow ups