Tejas Tank (OpenERP) has proposed merging
lp:~openerp-dev/openobject-server/trunk-methflow into lp:openobject-server.
Requested reviews:
OpenERP Core Team (openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-methflow/+merge/147027
Hello,
Improve workflow API:
* Use the new signal_xxx metho
* Similarly for trg_create/delete/redirect, use create_workflow,
delete_workflow, redirect_workflow.
In addons enhanced workflow api by signals_xxx and
[create/delete/redirect]_workflow.
Thanks,
TTA
--
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-methflow/+merge/147027
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-server/trunk-methflow.
=== modified file 'doc/index.rst'
--- doc/index.rst 2013-02-05 17:23:41 +0000
+++ doc/index.rst 2013-02-07 07:04:23 +0000
@@ -35,6 +35,7 @@
.. toctree::
:maxdepth: 1
+ orm-methods.rst
api_models.rst
Concepts
=== added file 'doc/orm-methods.rst'
--- doc/orm-methods.rst 1970-01-01 00:00:00 +0000
+++ doc/orm-methods.rst 2013-02-07 07:04:23 +0000
@@ -0,0 +1,51 @@
+.. _orm-methods:
+
+ORM methods
+===========
+
+.. _orm-workflows:
+
+Workflow-related methods
+------------------------
+
+.. versionadded:: 7.1
+
+Creating, deleting, or otherwise manipulating workflow instances is possible
+right from a Model instance. (Previously, workflows were handled throught a
+call to ``LocalService('workflow')``. Using the ORM methods is now the preferred
+way.)
+
+.. currentmodule:: openerp.osv.orm
+
+.. automethod:: BaseModel.create_workflow
+ :noindex:
+
+ This is used instead of ``LocalService('workflow').trg_create()``.
+
+.. automethod:: BaseModel.delete_workflow
+ :noindex:
+
+ This is used instead of ``LocalService('workflow').trg_delete()``.
+
+.. automethod:: BaseModel.redirect_workflow
+ :noindex:
+
+.. method:: BaseModel.signal_xxx(cr, uid, ids)
+ :noindex:
+
+ Sends a signal ``xxx`` to the workflow instances bound to the given record
+ IDs. (This is implemented using ``__getattr__`` so no source link is
+ rendered on the right.)
+
+ This is used instead of ``LocalService('workflow').trg_validate()``.
+
+
+.. note::
+ Low-level access to the workflows is still possible by using the
+ ``openerp.workflow`` module, that is, in a similar way to what was possible
+ with the previous ``LocalService('workflow')`` access. This may be useful
+ when looking-up a model in the registry and/or its records is not necessary.
+ For instance when working with raw model names and record IDs is preferred (to
+ avoid hitting unnecessarily the database). But this is something that should be
+ carefully considered as it would bypass the ORM methods (and thus any inherited
+ behaviors).
=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py 2013-01-16 16:40:25 +0000
+++ openerp/osv/orm.py 2013-02-07 07:04:23 +0000
@@ -3928,6 +3928,31 @@
result[res_id] = wf_service.trg_validate(uid, self._name, res_id, signal, cr)
return result
+ def create_workflow(self, cr, uid, ids):
+ """Create a workflow instance for each given record IDs."""
+ wf_service = netsvc.LocalService("workflow")
+ for res_id in ids:
+ wf_service.trg_create(uid, self._name, res_id, cr)
+ return True
+
+ def delete_workflow(self, cr, uid, ids):
+ """Delete the workflow instances bound to the given record IDs."""
+ wf_service = netsvc.LocalService("workflow")
+ for res_id in ids:
+ wf_service.trg_create(uid, self._name, res_id, cr)
+ return True
+
+ def redirect_workflow(self, cr, uid, old_new_ids):
+ """
+ Rebind the workflow instance bound to the given 'old' record IDs to
+ the given 'new' IDs. (``old_new_ids`` is a list of pairs
+ ``(old, new)``.
+ """
+ wf_service = netsvc.LocalService("workflow")
+ for old_id, new_id in old_new_ids:
+ wf_service.trg_redirect(uid, self._name, old_id, new_id, cr)
+ return True
+
def unlink(self, cr, uid, ids, context=None):
"""
Delete records with given ids
@@ -5251,6 +5276,20 @@
""" 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
+ return super(BaseModel, self).__getattr__(name)
+
# keep this import here, at top it will cause dependency cycle errors
import expression
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp