From 84ff1da4d997d9250aa6586d26761f5b65021152 Mon Sep 17 00:00:00 2001 From: Bertrand Chenal Date: Tue, 20 May 2008 22:58:57 +0200 Subject: [PATCH] Added check on workflow creation: Ensure that there is not already an existing active workflow for the record. --- trytond/wkf_service/wkf_service.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/trytond/wkf_service/wkf_service.py b/trytond/wkf_service/wkf_service.py index bd687595de..43dc181b2f 100644 --- a/trytond/wkf_service/wkf_service.py +++ b/trytond/wkf_service/wkf_service.py @@ -1,5 +1,6 @@ "Workflow service" from trytond.netsvc import Service +from trytond.osv import ExceptOSV import instance @@ -58,6 +59,15 @@ class WorkflowService(Service): wkf_ids = cursor.fetchall() self.wkf_on_create_cache[cursor.dbname][res_type] = wkf_ids for (wkf_id,) in wkf_ids: + cursor.execute( + "SELECT id FROM wkf_instance " \ + "WHERE res_type = %s AND res_id = %s "\ + "AND workflow = %s AND state = 'active'", + (res_type, res_id, wkf_id,)) + if cursor.rowcount: + raise ExceptOSV("Error", "Another active workflow already "\ + "exist for this record: %s@%s."% \ + (res_id, res_type)) instance.create(cursor, ident, wkf_id) def trg_validate(self, user, res_type, res_id, signal, cursor):