[MERGE] trunk-methflow-thu (refactor existing workflow methods in models)
bzr revid: rco@openerp.com-20130213151005-bchqq38zqn03thek
This commit is contained in:
commit
9f7918d815
|
@ -3910,43 +3910,42 @@ class BaseModel(object):
|
||||||
returned_ids = [x['id'] for x in cr.dictfetchall()]
|
returned_ids = [x['id'] for x in cr.dictfetchall()]
|
||||||
self._check_record_rules_result_count(cr, uid, sub_ids, returned_ids, operation, context=context)
|
self._check_record_rules_result_count(cr, uid, sub_ids, returned_ids, operation, context=context)
|
||||||
|
|
||||||
def _workflow_trigger(self, cr, uid, ids, trigger, context=None):
|
def create_workflow(self, cr, uid, ids, context=None):
|
||||||
"""Call given workflow trigger as a result of a CRUD operation"""
|
"""Create a workflow instance for each given record IDs."""
|
||||||
wf_service = netsvc.LocalService("workflow")
|
from openerp import workflow
|
||||||
for res_id in ids:
|
for res_id in ids:
|
||||||
getattr(wf_service, trigger)(uid, self._name, res_id, cr)
|
workflow.trg_create(uid, self._name, res_id, cr)
|
||||||
|
return True
|
||||||
|
|
||||||
def _workflow_signal(self, cr, uid, ids, signal, context=None):
|
def delete_workflow(self, cr, uid, ids, context=None):
|
||||||
|
"""Delete the workflow instances bound to the given record IDs."""
|
||||||
|
from openerp import workflow
|
||||||
|
for res_id in ids:
|
||||||
|
workflow.trg_delete(uid, self._name, res_id, cr)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def step_workflow(self, cr, uid, ids, context=None):
|
||||||
|
"""Reevaluate the workflow instances of the given record IDs."""
|
||||||
|
from openerp import workflow
|
||||||
|
for res_id in ids:
|
||||||
|
workflow.trg_write(uid, self._name, res_id, cr)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def signal_workflow(self, cr, uid, ids, signal, context=None):
|
||||||
"""Send given workflow signal and return a dict mapping ids to workflow results"""
|
"""Send given workflow signal and return a dict mapping ids to workflow results"""
|
||||||
wf_service = netsvc.LocalService("workflow")
|
from openerp import workflow
|
||||||
result = {}
|
result = {}
|
||||||
for res_id in ids:
|
for res_id in ids:
|
||||||
result[res_id] = wf_service.trg_validate(uid, self._name, res_id, signal, cr)
|
result[res_id] = workflow.trg_validate(uid, self._name, res_id, signal, cr)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def create_workflow(self, cr, uid, ids):
|
def redirect_workflow(self, cr, uid, old_new_ids, context=None):
|
||||||
"""Create a workflow instance for each given record IDs."""
|
""" Rebind the workflow instance bound to the given 'old' record IDs to
|
||||||
wf_service = netsvc.LocalService("workflow")
|
the given 'new' IDs. (``old_new_ids`` is a list of pairs ``(old, new)``.
|
||||||
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
|
from openerp import workflow
|
||||||
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:
|
for old_id, new_id in old_new_ids:
|
||||||
wf_service.trg_redirect(uid, self._name, old_id, new_id, cr)
|
workflow.trg_redirect(uid, self._name, old_id, new_id, cr)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def unlink(self, cr, uid, ids, context=None):
|
def unlink(self, cr, uid, ids, context=None):
|
||||||
|
@ -3987,7 +3986,7 @@ class BaseModel(object):
|
||||||
property_ids = ir_property.search(cr, uid, [('res_id', 'in', ['%s,%s' % (self._name, i) for i in ids])], context=context)
|
property_ids = ir_property.search(cr, uid, [('res_id', 'in', ['%s,%s' % (self._name, i) for i in ids])], context=context)
|
||||||
ir_property.unlink(cr, uid, property_ids, context=context)
|
ir_property.unlink(cr, uid, property_ids, context=context)
|
||||||
|
|
||||||
self._workflow_trigger(cr, uid, ids, 'trg_delete', context=context)
|
self.delete_workflow(cr, uid, ids, context=context)
|
||||||
|
|
||||||
self.check_access_rule(cr, uid, ids, 'unlink', context=context)
|
self.check_access_rule(cr, uid, ids, 'unlink', context=context)
|
||||||
pool_model_data = self.pool.get('ir.model.data')
|
pool_model_data = self.pool.get('ir.model.data')
|
||||||
|
@ -4292,7 +4291,7 @@ class BaseModel(object):
|
||||||
todo.append(id)
|
todo.append(id)
|
||||||
self.pool.get(object)._store_set_values(cr, user, todo, fields_to_recompute, context)
|
self.pool.get(object)._store_set_values(cr, user, todo, fields_to_recompute, context)
|
||||||
|
|
||||||
self._workflow_trigger(cr, user, ids, 'trg_write', context=context)
|
self.step_workflow(cr, user, ids, context=context)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -4508,7 +4507,7 @@ class BaseModel(object):
|
||||||
self.name_get(cr, user, [id_new], context=context)[0][1] + \
|
self.name_get(cr, user, [id_new], context=context)[0][1] + \
|
||||||
"' " + _("created.")
|
"' " + _("created.")
|
||||||
self.log(cr, user, id_new, message, True, context=context)
|
self.log(cr, user, id_new, message, True, context=context)
|
||||||
self._workflow_trigger(cr, user, [id_new], 'trg_create', context=context)
|
self.create_workflow(cr, user, [id_new], context=context)
|
||||||
return id_new
|
return id_new
|
||||||
|
|
||||||
def browse(self, cr, uid, select, context=None, list_class=None, fields_process=None):
|
def browse(self, cr, uid, select, context=None, list_class=None, fields_process=None):
|
||||||
|
@ -5276,14 +5275,8 @@ class BaseModel(object):
|
||||||
if name.startswith('signal_'):
|
if name.startswith('signal_'):
|
||||||
signal_name = name[len('signal_'):]
|
signal_name = name[len('signal_'):]
|
||||||
assert signal_name
|
assert signal_name
|
||||||
def handle_workflow_signal(cr, uid, ids, context=None):
|
return (lambda *args, **kwargs:
|
||||||
workflow_service = netsvc.LocalService("workflow")
|
self.signal_workflow(*args, signal=signal_name, **kwargs))
|
||||||
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)
|
return super(BaseModel, self).__getattr__(name)
|
||||||
|
|
||||||
# keep this import here, at top it will cause dependency cycle errors
|
# keep this import here, at top it will cause dependency cycle errors
|
||||||
|
|
|
@ -166,7 +166,7 @@ def exec_workflow_cr(cr, uid, obj, signal, *args):
|
||||||
if not object:
|
if not object:
|
||||||
raise except_orm('Object Error', 'Object %s doesn\'t exist' % str(obj))
|
raise except_orm('Object Error', 'Object %s doesn\'t exist' % str(obj))
|
||||||
res_id = args[0]
|
res_id = args[0]
|
||||||
return object._workflow_signal(cr, uid, [res_id], signal)[res_id]
|
return object.signal_workflow(cr, uid, [res_id], signal)[res_id]
|
||||||
|
|
||||||
@check
|
@check
|
||||||
def exec_workflow(db, uid, obj, signal, *args):
|
def exec_workflow(db, uid, obj, signal, *args):
|
||||||
|
|
Loading…
Reference in New Issue