def get_triggered_tasks(cr, uid, task_id, context=None): """ Get the triggered tasks from the task ID :param cr: Odoo cursor :param uid: User ID getting the triggered tasks :param task_id: ID of the activity checking triggered tasks of :param context: Odoo context :return: list of triggered task dicts """ env = Environment(cr, uid, {}) api_model = env.registry('nh.clinical.api') activity_model = env.registry('nh.activity') triggered_ids = activity_model.search( cr, uid, [['creator_id', '=', int(task_id)]]) triggered_tasks_read = activity_model.read(cr, uid, triggered_ids) triggered_tasks = [] for trig_task in triggered_tasks_read: access = api_model.check_activity_access(cr, uid, trig_task['id'], context=context) is_not_ob = 'ews' not in trig_task['data_model'] if access and is_not_ob: triggered_tasks.append(trig_task) return triggered_tasks
def complete_notification(self, cr, uid, task_id, vals=None, context=None): """ Complete notifcation and return JSON object ready to send back to frontend :param cr: Odoo Cursor :param uid: User doing the action :param task_id: ID of the notification to complete :param vals: dict of values to send as part of complete :param context: Odoo context :return: JSON string of response """ if not vals: vals = {} task_id = int(task_id) env = Environment(cr, uid, {}) api_pool = env.registry('nh.eobs.api') try: api_pool.complete(cr, uid, task_id, vals) except osv.except_osv: response_data = { 'error': 'The server returned an error while trying ' 'to complete the task.' } return ResponseJSON.get_json_data( status=ResponseJSON.STATUS_ERROR, title='Submission unsuccessful', description='Unable to complete the notification', data=response_data ) activity_model = env.registry('nh.activity') activity = activity_model.read(cr, uid, task_id) patient_name = activity.get('patient_id')[1] description = 'All escalation tasks for <strong>{}</strong> ' \ 'have been completed'.format(patient_name) excluded_notification_models = [ 'nh.clinical.notification.nurse', 'nh.clinical.notification.hca' ] if activity.get('data_model') in excluded_notification_models: description = 'The notification was successfully submitted' triggered_tasks = \ self.get_triggered_tasks(cr, uid, task_id, context=context) response_data = {'related_tasks': triggered_tasks, 'status': 1} return ResponseJSON.get_json_data( status=ResponseJSON.STATUS_SUCCESS, title='Submission successful', description=description, data=response_data )
def cancel_notification(self, cr, uid, task_id, vals=None, context=None): """ Cancel notification and send JSON response ready to send back to the frontend :param cr: Odoo cursor :param uid: User ID cancelling notification :param task_id: ID of the notification being cancelled :param vals: dictionary of values to send as part of cancel :param context: Odoo context :return: JSON string of response """ if not vals: vals = {} env = Environment(cr, uid, {}) api_pool = env.registry('nh.eobs.api') task_id = int(task_id) try: api_pool.cancel(cr, uid, task_id, vals) except osv.except_osv: response_data = { 'error': 'The server returned an error while trying ' 'to cancel the task.' } return ResponseJSON.get_json_data( status=ResponseJSON.STATUS_ERROR, title='Cancellation unsuccessful', description='Unable to cancel the notification', data=response_data) activity_model = env.registry('nh.activity') patient_name = activity_model.read(cr, uid, task_id, ['patient_id'])['patient_id'][1] description = 'All escalation tasks for <strong>{}</strong> ' \ 'have been completed'.format(patient_name) triggered_tasks = self.get_triggered_tasks(cr, uid, task_id, context=context) response_data = {'related_tasks': triggered_tasks, 'status': 4} return ResponseJSON.get_json_data(status=ResponseJSON.STATUS_SUCCESS, title='Cancellation successful', description=description, data=response_data)