def validate(self, signal): result = False # ids of all active workflow instances for a corresponding resource (id, model_nam) self.cr.execute('select id from wkf_instance where res_id=%s and res_type=%s and state=%s', (self.record.id, self.record.model, 'active')) # TODO: Refactor the workflow instance object for (instance_id,) in self.cr.fetchall(): wi = WorkflowInstance(self.session, self.record, {'id': instance_id}) res2 = wi.validate(signal) result = result or res2 return result
def create(self): WorkflowService.CACHE.setdefault(self.cr.dbname, {}) wkf_ids = WorkflowService.CACHE[self.cr.dbname].get(self.record.model, None) if not wkf_ids: self.cr.execute('select id from wkf where osv=%s and on_create=True', (self.record.model,)) wkf_ids = self.cr.fetchall() WorkflowService.CACHE[self.cr.dbname][self.record.model] = wkf_ids for (wkf_id, ) in wkf_ids: WorkflowInstance.create(self.session, self.record, wkf_id)
def validate(self, signal): result = False # ids of all active workflow instances for a corresponding resource (id, model_nam) self.cr.execute( 'select id from wkf_instance where res_id=%s and res_type=%s and state=%s', (self.record.id, self.record.model, 'active')) # TODO: Refactor the workflow instance object for (instance_id, ) in self.cr.fetchall(): wi = WorkflowInstance(self.session, self.record, {'id': instance_id}) res2 = wi.validate(signal) result = result or res2 return result
def create(self): WorkflowService.CACHE.setdefault(self.cr.dbname, {}) wkf_ids = WorkflowService.CACHE[self.cr.dbname].get( self.record.model, None) if not wkf_ids: self.cr.execute( 'select id from wkf where osv=%s and on_create=True', (self.record.model, )) wkf_ids = self.cr.fetchall() WorkflowService.CACHE[self.cr.dbname][self.record.model] = wkf_ids for (wkf_id, ) in wkf_ids: WorkflowInstance.create(self.session, self.record, wkf_id)
def write(self): self.cr.execute( 'select id from wkf_instance where res_id=%s and res_type=%s and state=%s', (self.record.id or None, self.record.model or None, 'active')) for (instance_id, ) in self.cr.fetchall(): WorkflowInstance(self.session, self.record, { 'id': instance_id }).update()
def trigger(self): self.cr.execute( 'select instance_id from wkf_triggers where res_id=%s and model=%s', (self.record.id, self.record.model)) res = self.cr.fetchall() for (instance_id, ) in res: self.cr.execute( 'select %s,res_type,res_id from wkf_instance where id=%s', ( self.session.uid, instance_id, )) current_uid, current_model_name, current_record_id = self.cr.fetchone( ) current_session = Session(self.session.cr, current_uid) current_record = Record(current_model_name, current_record_id) WorkflowInstance(current_session, current_record, { 'id': instance_id }).update()
def delete(self): WorkflowInstance(self.session, self.record, {}).delete()