[FIX] anonymization: raise a good descriptive error when the state is 'unstable'
authorolt@tinyerp.com <>
Mon, 17 Sep 2012 08:10:17 +0000 (10:10 +0200)
committerolt@tinyerp.com <>
Mon, 17 Sep 2012 08:10:17 +0000 (10:10 +0200)
bzr revid: olt@tinyerp.com-20120917081017-s15mm36ppvs4lfxc

addons/anonymization/anonymization.py

index 47e168a..6b6db16 100644 (file)
@@ -64,11 +64,13 @@ class ir_model_fields_anonymization(osv.osv):
             state = 'anonymized' # all fields are anonymized
         else:
             state = 'unstable' # fields are mixed: this should be fixed
+
         return state
 
     def _check_write(self, cr, uid, context=None):
         # check that the field is created from the menu and not from an database update
         # otherwise the database update can crash:
+
         if context.get('manual'):
             global_state = self._get_global_state(cr, uid, context=context)
             if global_state == 'anonymized':
@@ -100,12 +102,16 @@ class ir_model_fields_anonymization(osv.osv):
         # check field state: all should be clear before we can add a new field to anonymize:
         self._check_write(cr, uid, context=context)
 
+        global_state = self._get_global_state(cr, uid, context=context)
+
         if 'field_name' in vals and vals['field_name'] and 'model_name' in vals and vals['model_name']:
             vals['model_id'], vals['field_id'] = self._get_model_and_field_ids(cr, uid, vals, context=context)
 
         # check not existing fields:
         if not vals.get('field_id'):
             vals['state'] = 'not_existing'
+        else:
+            vals['state'] = global_state
 
         res = super(ir_model_fields_anonymization, self).create(cr, uid, vals, context=context)
 
@@ -340,8 +346,9 @@ class ir_model_fields_anonymize_wizard(osv.osv_memory):
                 # remove the placeholer:
                 eview.remove(placeholder)
             else:
-                # unstable ?
-                raise
+                msg = "The database anonymization is currently in an unstable state. Some fields are anonymized," + \
+                  " while some fields are not anonymized. You should try to solve this problem before trying to do anything else."
+                raise osv.except_osv('Error !', msg)
 
             res['arch'] = etree.tostring(eview)