[IMP] orm: expose a signal_xxx() method to call workflow.trg_validate().
authorVo Minh Thu <vmt@openerp.com>
Fri, 25 Jan 2013 15:51:32 +0000 (16:51 +0100)
committerVo Minh Thu <vmt@openerp.com>
Fri, 25 Jan 2013 15:51:32 +0000 (16:51 +0100)
bzr revid: vmt@openerp.com-20130125155132-nhyntobe5xm1g7h0

openerp/osv/orm.py

index 6056e40..0ffabcf 100644 (file)
@@ -5251,6 +5251,20 @@ class BaseModel(object):
         """ stuff to do right after the registry is built """
         pass
 
+    def __getattr__(self, name):
+        if name.startswith('signal_'):
+            signal_name = name[len('signal_'):]
+            assert signal_name
+            def handle_workflow_signal(cr, uid, ids):
+                workflow_service = netsvc.LocalService("workflow")
+                res = {}
+                for id in ids:
+                    # TODO consolidate trg_validate() and the functions it calls to work on a list of IDs.
+                    res[id] = workflow_service.trg_validate(uid, self._name, id, signal_name, cr)
+                return res
+            return handle_workflow_signal
+        raise AttributeError
+
 # keep this import here, at top it will cause dependency cycle errors
 import expression