Esempio n. 1
0
 def open_case(self, name, description, client_id,
               user_id, handler_id=None):
     if handler_id is None:
         handler_id = user_id
     d = self.descriptions.new(description)
     with transaction.manager:
         now = datetime.now()
         c = Case()
         c.name = name
         c.client_id = client_id
         c.description_id = d.id
         c.created = now
         c.created_by_id = user_id
         self.session.add(c)
         c = self.session.merge(c)
         change = CaseStatusChange()
         change.case_id = c.id
         change.status = 'opened'
         change.reason = 'New Case'
         change.description_id = d.id
         change.changed = now
         change.changed_by_id = user_id
         change.handler_id = handler_id
         self.session.add(change)
         change = self.session.merge(change)
         current = CaseCurrentStatus()
         current.case_id = c.id
         current.last_change_id = change.id
         current.created = c.created
         current.last_change = change.changed
         current.status = change.status
         current.changed_by_id = user_id
         current.handler_id = handler_id
         self.session.add(current)
         cu = CaseUser()
         cu.case_id = c.id
         cu.user_id = user_id
         self.session.add(cu)
     return self.session.merge(c)
Esempio n. 2
0
 def update_case(self, case_id, user_id, status, reason, handler_id,
                 description=None):
     with transaction.manager:
         now = datetime.now()
         case = self.get(case_id)
         change = CaseStatusChange()
         change.case_id = case_id
         change.status = status
         change.reason = reason
         change.changed = now
         change.changed_by_id = user_id
         change.handler_id = handler_id
         if description is None:
             change.description_id = case.description_id
         self.session.add(change)
         change = self.session.merge(change)
         current = self.session.query(CaseCurrentStatus).get(case_id)
         current.last_change = now
         current.last_change_id = change.id
         current.status = status
         current.changed_by_id = user_id
         current.handler_id = handler_id
         current = self.session.merge(current)
     return self.session.merge(change)