← Back to team overview

openerp-dev-web team mailing list archive

lp:~openerp-dev/openobject-addons/addons-training-evaluation-category-constrain-recursive-ysa into lp:~openobject-training/openobject-addons/training

 

Yogesh(Open ERP) has proposed merging lp:~openerp-dev/openobject-addons/addons-training-evaluation-category-constrain-recursive-ysa into lp:~openobject-training/openobject-addons/training.

Requested reviews:
  OpenObject Training (openobject-training)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/addons-training-evaluation-category-constrain-recursive-ysa/+merge/59167

[FIX] training_evaluation :- add check_recursion constrain in training_evaluation_category object.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/addons-training-evaluation-category-constrain-recursive-ysa/+merge/59167
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/addons-training-evaluation-category-constrain-recursive-ysa.
=== modified file 'training_evaluation/training_evaluation.py'
--- training_evaluation/training_evaluation.py	2011-04-11 08:57:50 +0000
+++ training_evaluation/training_evaluation.py	2011-04-27 05:48:38 +0000
@@ -75,6 +75,20 @@
         'type' : lambda *a: 'lecturer',
     }
 
+    def _check_recursion(self, cr, uid, ids, context=None):
+        level = 100
+        while len(ids):
+            cr.execute('select distinct parent_id from training_evaluation_category where id in ('+','.join(map(str,ids))+')')
+            ids = filter(None, map(lambda x:x[0], cr.fetchall()))
+            if not level:
+                return False
+            level -= 1
+        return True
+
+    _constraints = [
+        (_check_recursion, 'Error! You can not create recursive Evaluation Categories.', ['parent_id'])
+    ]
+
     def on_change_parent(self, cr, uid, ids, parent_id, context=None):
         if context is None:
             context = {}


Follow ups