diff --git a/nh_clinical/__openerp__.py b/nh_clinical/__openerp__.py
index c732e070..be67d23b 100644
--- a/nh_clinical/__openerp__.py
+++ b/nh_clinical/__openerp__.py
@@ -32,7 +32,7 @@
'demo': ['data/test/locations.xml', 'data/test/users.xml'],
'css': [],
'js': [],
- 'qweb': [],
+ 'qweb': ['static/src/xml/form_tree_selected_widget_template.xml'],
'images': [],
'application': True,
'installable': True,
diff --git a/nh_clinical/static/src/js/form_tree_selected_widget.js b/nh_clinical/static/src/js/form_tree_selected_widget.js
new file mode 100644
index 00000000..1a97c0b1
--- /dev/null
+++ b/nh_clinical/static/src/js/form_tree_selected_widget.js
@@ -0,0 +1,37 @@
+openerp.nh_clinical = function (instance) {
+
+ var QWeb = instance.web.qweb;
+ var _t = instance.web._t;
+
+ // Declare our widget so it can be used on a view
+ instance.web.list.columns.add('field.form_tree_selected', 'instance.web.list.FormTreeSelectedColumn');
+
+ instance.web.list.FormTreeSelectedColumn = instance.web.list.Boolean.extend({
+
+ // Extend the format function of the boolean widget to add a click event to the node
+ format: function (row_data, options) {
+ var self = this;
+ var clickableId = "o_web_tree_selected_clickable-" +
+ row_data.id.value;
+
+ // defer execution of setting the click event until the function has returned
+ window.setTimeout(function() {
+ $("#" + clickableId).click(function() {
+ if( $('#' + clickableId + ':checkbox:checked').length > 0 ) {
+ // Make the RPC call with the value of true
+ new instance.web.Model("nh.clinical.allocating")
+ .call("write", [row_data.id.value], {'vals': {'selected': true}});
+ } else {
+ // Make the RPC call with the value of false
+ new instance.web.Model("nh.clinical.allocating")
+ .call("write", [row_data.id.value], {'vals': {'selected': false}});
+ }
+ });
+ }, 0);
+ return QWeb.render(
+ 'FormTreeSelected',
+ {widget: self._format(row_data, options), clickableId: clickableId}
+ );
+ },
+ });
+};
\ No newline at end of file
diff --git a/nh_clinical/static/src/xml/form_tree_selected_widget_template.xml b/nh_clinical/static/src/xml/form_tree_selected_widget_template.xml
new file mode 100644
index 00000000..47c305fc
--- /dev/null
+++ b/nh_clinical/static/src/xml/form_tree_selected_widget_template.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/nh_clinical/views/static_resources.xml b/nh_clinical/views/static_resources.xml
index 8ffe084e..bbd75d4d 100644
--- a/nh_clinical/views/static_resources.xml
+++ b/nh_clinical/views/static_resources.xml
@@ -3,6 +3,7 @@
+
diff --git a/nh_clinical/wizard/user_allocation.py b/nh_clinical/wizard/user_allocation.py
index c4edb271..b5969db7 100644
--- a/nh_clinical/wizard/user_allocation.py
+++ b/nh_clinical/wizard/user_allocation.py
@@ -1,6 +1,6 @@
# Part of NHClinical. See LICENSE file for full copyright and licensing details
# -*- coding: utf-8 -*-
-from openerp.osv import osv, fields
+from openerp import models, fields, api
def list_diff(a, b):
@@ -13,151 +13,188 @@ def list_intersect(a, b):
return [aa for aa in a if aa in b]
-class AllocationWizards(osv.AbstractModel):
+class AllocationWizards(models.AbstractModel):
_name = 'nh.clinical.allocation'
- _columns = {
- 'create_uid': fields.many2one(
- 'res.users',
- 'User Executing the Wizard'),
- 'create_date': fields.datetime('Create Date')
- }
+ create_uid = fields.Many2one(
+ 'res.users',
+ 'User Executing the Wizard')
+ create_date = fields.Datetime('Create Date')
- def responsibility_allocation_activity(self, cr, uid, user_id,
- location_ids, context=None):
+ def responsibility_allocation_activity(self, user_id, location_ids):
"""
Create and complete a responsibility allocation activity for location
:param location_ids: Ward ID
- :param context: A context
:return: True
"""
- activity_pool = self.pool['nh.activity']
- respallocation_pool = self.pool[
- 'nh.clinical.user.responsibility.allocation'
- ]
- activity_id = respallocation_pool.create_activity(
- cr, uid, {}, {
+ NhActivity = self.env['nh.activity']
+ NhClinicalUserResponsibilityAllocation = self.env['nh.clinical.user.responsibility.allocation']
+ activity_id = NhClinicalUserResponsibilityAllocation.create_activity({}, {
'responsible_user_id': user_id,
'location_ids': [[6, 0, location_ids]]
- }, context=context)
- activity_pool.complete(cr, uid, activity_id, context=context)
+ })
+ NhActivity.complete(activity_id)
return True
- def unfollow_patients_in_locations(self, cr, uid, location_ids,
- context=None):
+ def unfollow_patients_in_locations(self, location_ids):
"""
Unfollow any patients in the locations currently being reallocated
:param location_ids: List of location ids
- :param context: context for odoo
:return: True
"""
- activity_pool = self.pool['nh.activity']
- patient_pool = self.pool['nh.clinical.patient']
- unfollow_pool = self.pool['nh.clinical.patient.unfollow']
- patient_ids = patient_pool.search(
- cr, uid, [['current_location_id', 'in', location_ids]],
- context=context)
+ NhActivity = self.env['nh.activity']
+ NhClinicalPatient = self.env['nh.clinical.patient']
+ NhClinicalPatientUnfollow = self.env['nh.clinical.patient.unfollow']
+ patient_ids = NhClinicalPatient.search([['current_location_id', 'in', location_ids]]).ids
if patient_ids:
- unfollow_activity_id = unfollow_pool.create_activity(cr, uid, {}, {
- 'patient_ids': [[6, 0, patient_ids]]}, context=context)
- activity_pool.complete(cr, uid, unfollow_activity_id,
- context=context)
+ unfollow_activity = NhClinicalPatientUnfollow.create_activity({}, {
+ 'patient_ids': [[6, 0, patient_ids]]})
+ NhActivity.complete(unfollow_activity)
return True
- def complete(self, cr, uid, ids, context=None):
- if isinstance(ids, list):
- ids = ids[0]
- if not isinstance(ids, int):
- raise ValueError('Invalid ID passed to complete')
- allocating_pool = self.pool['nh.clinical.allocating']
- wizard = self.browse(cr, uid, ids, context=context)
+ @api.multi
+ def complete(self):
+ NhClinicalAllocating = self.env['nh.clinical.allocating']
allocation = {u.id: [l.id for l in u.location_ids] for u in
- wizard.user_ids}
- for allocating in allocating_pool.browse(
- cr, uid, [a.id for a in wizard.allocating_ids],
- context=context):
+ self.user_ids}
+ for allocating in self.allocating_ids:
if allocating.nurse_id:
- allocation[allocating.nurse_id.id].append(
- allocating.location_id.id)
- if allocating.nurse_id.id == uid:
- allocation[allocating.nurse_id.id].append(
- wizard.ward_id.id)
+ allocation[allocating.nurse_id.id].append(allocating.location_id.id)
+ if allocating.nurse_id.id == self.env.uid:
+ allocation[allocating.nurse_id.id].append(self.ward_id.id)
for hca in allocating.hca_ids:
allocation[hca.id].append(allocating.location_id.id)
for key, value in allocation.iteritems():
- self.responsibility_allocation_activity(cr, uid, key, value,
- context=context)
+ self.responsibility_allocation_activity(key, value)
return {'type': 'ir.actions.act_window_close'}
-class StaffAllocationWizard(osv.TransientModel):
+class StaffAllocationWizard(models.TransientModel):
_name = 'nh.clinical.staff.allocation'
_inherit = 'nh.clinical.allocation'
_rec_name = 'create_uid'
_stages = [['wards', 'My Ward'], ['review', 'De-allocate'],
- ['users', 'Roll Call'], ['allocation', 'Allocation']]
-
- _columns = {
- 'stage': fields.selection(_stages, string='Stage'),
- 'ward_id': fields.many2one('nh.clinical.location',
- string='Ward',
- domain=[['usage', '=', 'ward']]),
- 'location_ids': fields.many2many('nh.clinical.location',
- 'alloc_loc_rel', 'allocation_id',
- 'location_id',
- string='Locations'),
- 'user_ids': fields.many2many('res.users', 'alloc_user_rel',
- 'allocation_id', 'user_id',
- string='Users',
- domain=[
- ['groups_id.name', 'in',
- ['NH Clinical HCA Group',
- 'NH Clinical Nurse Group']]
- ]),
- 'allocating_ids': fields.many2many('nh.clinical.allocating',
- 'alloc_allocating_rel',
- 'allocation_id',
- 'allocating_id',
- string='Allocating Locations')
- }
+ ['users', 'Roll Call'], ['allocation', 'Allocation'],
+ ['batch_allocation', 'Batch Allocation']]
+
+
+ stage = fields.Selection(_stages, string='Stage')
+ ward_id = fields.Many2one('nh.clinical.location',
+ string='Ward',
+ domain=[['usage', '=', 'ward']])
+ location_ids = fields.Many2many('nh.clinical.location',
+ 'alloc_loc_rel', 'allocation_id',
+ 'location_id',
+ string='Locations')
+ user_ids = fields.Many2many('res.users', 'alloc_user_rel',
+ 'allocation_id', 'user_id',
+ string='Users',
+ domain=[
+ ['groups_id.name', 'in',
+ ['NH Clinical HCA Group',
+ 'NH Clinical Nurse Group']]
+ ])
+ allocating_ids = fields.Many2many('nh.clinical.allocating',
+ 'alloc_allocating_rel',
+ 'allocation_id',
+ 'allocating_id',
+ string='Allocating Locations')
+ # Clone the fields from nh.clinical.allocation to allow us to do the batch
+ # operation on this model, instead of a new modal.
+ nurse_id = fields.Many2one(
+ 'res.users', 'Responsible Nurse',
+ domain=[['groups_id.name', 'in', ['NH Clinical Nurse Group']]])
+ hca_ids = fields.Many2many(
+ 'res.users',
+ string='Responsible HCAs',
+ domain=[['groups_id.name', 'in', ['NH Clinical HCA Group']]])
+
+
_defaults = {
'stage': 'wards'
}
- def submit_ward(self, cr, uid, ids, context=None):
- if isinstance(ids, list):
- ids = ids[0]
- if not isinstance(ids, int):
- raise ValueError('Invalid ID passed to submit_wards')
- wiz = self.browse(cr, uid, ids, context=context)
- ward_ids = [wiz.ward_id.id]
- location_pool = self.pool['nh.clinical.location']
- location_ids = location_pool.search(
- cr, uid, [['id', 'child_of', ward_ids]], context=context)
- self.write(cr, uid, ids,
- {'stage': 'review', 'location_ids': [[6, 0, location_ids]]},
- context=context)
+ # We need to clone this function from nh.clinical.allocation to ensure
+ # the values which show up in nurse_id and hca_ids are correct
+ def fields_view_get(self, cr, uid, view_id=None, view_type='form',
+ context=None, toolbar=False, submenu=False):
+ res = super(StaffAllocationWizard, self).fields_view_get(cr, uid, view_id,
+ view_type, context,
+ toolbar, submenu)
+ allocation_pool = self.pool['nh.clinical.staff.allocation']
+ al_id = allocation_pool.search(cr, uid, [['create_uid', '=', uid]],
+ order='id desc')
+ allocation = True if al_id else False
+ if not al_id or view_type != 'form':
+ return res
+ else:
+ if allocation:
+ allocation = allocation_pool.browse(cr, uid, al_id[0],
+ context=context)
+ user_ids = [u.id for u in allocation.user_ids]
+ res['fields']['nurse_id']['domain'] = [
+ ['id', 'in', user_ids],
+ ['groups_id.name', 'in', ['NH Clinical Nurse Group']]
+ ]
+ res['fields']['hca_ids']['domain'] = [
+ ['id', 'in', user_ids],
+ ['groups_id.name', 'in', ['NH Clinical HCA Group']]
+ ]
+ return res
+
+ @api.multi
+ def confirm_batch(self):
+ self.write({'stage': 'allocation'})
+ for record in [x for x in self.allocating_ids if x.selected == True]:
+ record.write({
+ 'nurse_id': self.nurse_id.id,
+ 'hca_ids': [[6, 0, self.hca_ids.ids]]
+ })
+ self.write({'nurse_id': False, 'hca_ids': [[6, 0, []]]})
return {
'type': 'ir.actions.act_window',
'name': 'Nursing Shift Change',
'res_model': 'nh.clinical.staff.allocation',
- 'res_id': ids,
+ 'res_id': self.id,
'view_mode': 'form',
'target': 'new',
}
- def deallocate(self, cr, uid, ids, context=None):
- if isinstance(ids, list):
- ids = ids[0]
- if not isinstance(ids, int):
- raise ValueError('Invalid ID passed to deallocate')
- user_pool = self.pool['res.users']
- allocating_pool = self.pool['nh.clinical.allocating']
- wiz = self.browse(cr, uid, ids, context=context)
- location_ids = [location.id for location in wiz.location_ids]
- user_ids = user_pool.search(cr, uid, [
+ @api.multi
+ def batch_allocate(self):
+ self.write({'stage': 'batch_allocation'})
+ return {
+ 'type': 'ir.actions.act_window',
+ 'name': 'Nursing Shift Change',
+ 'res_model': 'nh.clinical.staff.allocation',
+ 'res_id': self.id,
+ 'view_mode': 'form',
+ 'target': 'new',
+ }
+
+ @api.multi
+ def submit_ward(self):
+ ward_ids = [self.ward_id.id]
+ NhClinicalLocation = self.env['nh.clinical.location']
+ location_ids = NhClinicalLocation.search([['id', 'child_of', ward_ids]]).ids
+ self.write({'stage': 'review', 'location_ids': [[6, 0, location_ids]]})
+ return {
+ 'type': 'ir.actions.act_window',
+ 'name': 'Nursing Shift Change',
+ 'res_model': 'nh.clinical.staff.allocation',
+ 'res_id': self.id,
+ 'view_mode': 'form',
+ 'target': 'new',
+ }
+
+ @api.multi
+ def deallocate(self):
+ ResUsers = self.env['res.users']
+ NhClinicalAllocating = self.env['nh.clinical.allocating']
+ location_ids = [location.id for location in self.location_ids]
+ user_ids = ResUsers.search([
['groups_id.name', 'in',
[
'NH Clinical HCA Group',
@@ -165,95 +202,85 @@ def deallocate(self, cr, uid, ids, context=None):
'NH Clinical Shift Coordinator Group'
]],
['location_ids', 'in', location_ids]
- ], context=context)
+ ])
for location_id in location_ids:
- user_pool.write(cr, uid, user_ids,
- {'location_ids': [[3, location_id]]},
- context=context)
- self.responsibility_allocation_activity(cr, uid, uid, [wiz.ward_id.id],
- context=context)
- self.unfollow_patients_in_locations(cr, uid, location_ids,
- context=context)
+ user_ids.write({'location_ids': [[3, location_id]]})
+ self.responsibility_allocation_activity(self.env.uid, [self.ward_id.id])
+ self.unfollow_patients_in_locations(location_ids)
allocating_ids = []
- for location in wiz.location_ids:
+ for location in self.location_ids:
if location.usage == 'bed':
- allocating_ids.append(
- allocating_pool.create(cr, uid, {
- 'location_id': location.id}, context=context))
- self.write(cr, uid, ids,
- {
- 'allocating_ids': [[6, 0, allocating_ids]],
- 'stage': 'users'
- }, context=context)
+ allocating_ids.append(NhClinicalAllocating.create({'location_id': location.id}).id)
+ self.write({
+ 'allocating_ids': [[6, 0, allocating_ids]],
+ 'stage': 'users'
+ })
return {
'type': 'ir.actions.act_window',
'name': 'Nursing Shift Change',
'res_model': 'nh.clinical.staff.allocation',
- 'res_id': ids,
+ 'res_id': self.id,
'view_mode': 'form',
'target': 'new',
}
- def submit_users(self, cr, uid, ids, context=None):
- if isinstance(ids, list):
- ids = ids[0]
- if not isinstance(ids, int):
- raise ValueError('Invalid ID passed to submit_users')
- self.write(cr, uid, ids, {'stage': 'allocation'}, context=context)
+ @api.multi
+ def submit_users(self):
+ self.write({'stage': 'allocation'})
return {
'type': 'ir.actions.act_window',
'name': 'Nursing Shift Change',
'res_model': 'nh.clinical.staff.allocation',
- 'res_id': ids,
+ 'res_id': self.id,
'view_mode': 'form',
'target': 'new',
}
-class StaffReallocationWizard(osv.TransientModel):
+class StaffReallocationWizard(models.TransientModel):
_name = 'nh.clinical.staff.reallocation'
_inherit = 'nh.clinical.allocation'
_rec_name = 'create_uid'
_nursing_groups = ['NH Clinical Nurse Group', 'NH Clinical HCA Group']
- _stages = [['users', 'Current Roll Call'], ['allocation', 'Allocation']]
+ _stages = [['users', 'Current Roll Call'], ['allocation', 'Allocation'], ['batch_allocation', 'Batch Allocation']]
- def _get_default_ward(self, cr, uid, context=None):
- location_pool = self.pool['nh.clinical.location']
- ward_ids = location_pool.search(
- cr, uid, [['usage', '=', 'ward'], ['user_ids', 'in', [uid]]],
- context=context)
+ @api.multi
+ def _get_default_ward(self):
+ NhClinicalLocation = self.env['nh.clinical.location']
+ ward_ids = NhClinicalLocation.search([['usage', '=', 'ward'], ['user_ids', 'in', [self.env.uid]]])
if not ward_ids:
raise osv.except_osv(
'Shift Management Error!',
'You must be in charge of a ward to do this task!')
return ward_ids[0]
- def get_users_for_locations(self, cr, uid, location_ids, context=None):
- user_pool = self.pool['res.users']
- return user_pool.search(
- cr, uid, [['groups_id.name', 'in', self._nursing_groups],
- ['location_ids', 'in', location_ids]], context=context)
-
- def _get_default_users(self, cr, uid, context=None):
- location_ids = self._get_default_locations(cr, uid, context=context)
- return self.get_users_for_locations(cr, uid, location_ids,
- context=context)
-
- def _get_default_locations(self, cr, uid, context=None):
- location_pool = self.pool['nh.clinical.location']
- ward_id = self._get_default_ward(cr, uid, context=context)
- location_ids = location_pool.search(cr, uid,
- [['id', 'child_of', ward_id]],
- context=context)
- return location_ids
+ def get_users_for_locations(self, locations):
+ ResUsers = self.env['res.users']
+ if not isinstance(locations, list):
+ locations = locations.ids
+ return ResUsers.search([
+ ['groups_id.name', 'in', self._nursing_groups],
+ ['location_ids', 'in', locations]]
+ )
- def _get_default_allocatings(self, cr, uid, context=None):
- location_pool = self.pool['nh.clinical.location']
- allocating_pool = self.pool['nh.clinical.allocating']
- location_ids = self._get_default_locations(cr, uid, context=context)
- locations = location_pool.browse(cr, uid, location_ids,
- context=context)
+ @api.multi
+ def _get_default_users(self):
+ locations = self._get_default_locations()
+ return self.get_users_for_locations(locations)
+
+ @api.multi
+ def _get_default_locations(self):
+ NhClinicalLocation = self.env['nh.clinical.location']
+ ward_id = self._get_default_ward()
+ locations = NhClinicalLocation.search([['id', 'child_of', ward_id.id]])
+ return locations
+
+ @api.model
+ def _get_default_allocatings(self):
+ NhClinicalLocation = self.env['nh.clinical.location']
+ NhClinicalAllocating = self.env['nh.clinical.allocating']
+ locations = self._get_default_locations()
allocating_ids = []
for l in locations:
if l.usage != 'bed':
@@ -270,36 +297,45 @@ def _get_default_allocatings(self, cr, uid, context=None):
if 'NH Clinical Shift Coordinator Group' in groups \
and not nurse_id:
nurse_id = u.id
- allocating_ids.append(allocating_pool.create(cr, uid, {
+ allocating_ids.append(NhClinicalAllocating.create({
'location_id': l.id,
'nurse_id': nurse_id,
'hca_ids': [[6, 0, hca_ids]]
- }, context=context))
+ }).id)
return allocating_ids
- _columns = {
- 'stage': fields.selection(_stages, string='Stage'),
- 'ward_id': fields.many2one('nh.clinical.location',
- string='Ward',
- domain=[['usage', '=', 'ward']]),
- 'location_ids': fields.many2many('nh.clinical.location',
- 'realloc_loc_rel', 'reallocation_id',
- 'location_id',
- string='Locations'),
- 'user_ids': fields.many2many('res.users', 'realloc_user_rel',
- 'allocation_id', 'user_id',
- string='Users',
- domain=[
- ['groups_id.name', 'in',
- ['NH Clinical HCA Group',
- 'NH Clinical Nurse Group']]
- ]),
- 'allocating_ids': fields.many2many('nh.clinical.allocating',
- 'real_allocating_rel',
- 'reallocation_id',
- 'allocating_id',
- string='Allocating Locations')
- }
+ stage = fields.Selection(_stages, string='Stage')
+ ward_id = fields.Many2one('nh.clinical.location',
+ string='Ward',
+ domain=[['usage', '=', 'ward']])
+ location_ids = fields.Many2many('nh.clinical.location',
+ 'realloc_loc_rel', 'reallocation_id',
+ 'location_id',
+ string='Locations')
+ user_ids = fields.Many2many('res.users', 'realloc_user_rel',
+ 'allocation_id', 'user_id',
+ string='Users',
+ domain=[
+ ['groups_id.name', 'in',
+ ['NH Clinical HCA Group',
+ 'NH Clinical Nurse Group']]
+ ])
+ allocating_ids = fields.Many2many('nh.clinical.allocating',
+ 'real_allocating_rel',
+ 'reallocation_id',
+ 'allocating_id',
+ string='Allocating Locations')
+ # These fields are copied from nh.clinical.allocating, needed for our batch.
+ # I would have put them in a new 'batch' model, but doing anything other than an edit
+ # in a new modal closes the previous one, so instead we're just changing the stage of the existing one
+ nurse_id = fields.Many2one(
+ 'res.users', 'Responsible Nurse',
+ domain=[['groups_id.name', 'in', ['NH Clinical Nurse Group']]])
+ hca_ids = fields.Many2many(
+ 'res.users',
+ string='Responsible HCAs',
+ domain=[['groups_id.name', 'in', ['NH Clinical HCA Group']]])
+
_defaults = {
'stage': 'users',
'ward_id': _get_default_ward,
@@ -308,80 +344,141 @@ def _get_default_allocatings(self, cr, uid, context=None):
'allocating_ids': _get_default_allocatings
}
- def reallocate(self, cr, uid, ids, context=None):
- if isinstance(ids, list):
- ids = ids[0]
- if not isinstance(ids, int):
- raise ValueError('reallocate expected integer')
- user_pool = self.pool['res.users']
- wiz = self.read(
- cr, uid, ids, ['location_ids', 'user_ids'], context=context)
+ def fields_view_get(self, cr, uid, view_id=None, view_type='form',
+ context=None, toolbar=False, submenu=False):
+ res = super(StaffReallocationWizard, self).fields_view_get(cr, uid, view_id,
+ view_type, context,
+ toolbar, submenu)
+ allocation_pool = self.pool['nh.clinical.staff.allocation']
+ reallocation_pool = self.pool['nh.clinical.staff.reallocation']
+ al_id = allocation_pool.search(cr, uid, [['create_uid', '=', uid]],
+ order='id desc')
+ real_id = reallocation_pool.search(cr, uid, [['create_uid', '=', uid]],
+ order='id desc')
+ allocation = True if al_id else False
+ if al_id and real_id:
+ al = allocation_pool.browse(cr, uid, al_id[0], context=context)
+ real = reallocation_pool.browse(cr, uid, real_id[0],
+ context=context)
+ allocation = True if al.create_date > real.create_date else False
+ if not (al_id or real_id) or view_type != 'form':
+ return res
+ else:
+ if allocation:
+ allocation = allocation_pool.browse(cr, uid, al_id[0],
+ context=context)
+ user_ids = [u.id for u in allocation.user_ids]
+ res['fields']['nurse_id']['domain'] = [
+ ['id', 'in', user_ids],
+ ['groups_id.name', 'in', ['NH Clinical Nurse Group']]
+ ]
+ res['fields']['hca_ids']['domain'] = [
+ ['id', 'in', user_ids],
+ ['groups_id.name', 'in', ['NH Clinical HCA Group']]
+ ]
+ else:
+ reallocation = reallocation_pool.browse(cr, uid, real_id[0],
+ context=context)
+ user_ids = [u.id for u in reallocation.user_ids]
+ res['fields']['nurse_id']['domain'] = [
+ ['id', 'in', user_ids],
+ ['groups_id.name', 'in', ['NH Clinical Nurse Group']]
+ ]
+ res['fields']['hca_ids']['domain'] = [
+ ['id', 'in', user_ids],
+ ['groups_id.name', 'in', ['NH Clinical HCA Group']]
+ ]
+ return res
+
+
+ @api.multi
+ def confirm_batch(self):
+ self.write({'stage': 'allocation'})
+ for record in [x for x in self.allocating_ids if x.selected == True]:
+ record.write({
+ 'nurse_id': self.nurse_id.id,
+ 'hca_ids': [[6, 0, self.hca_ids.ids]]
+ })
+ # Clear the field
+ self.write({'nurse_id': False, 'hca_ids': [[6, 0, []]]})
+ return {
+ 'type': 'ir.actions.act_window',
+ 'name': 'Nursing Re-Allocation',
+ 'res_model': 'nh.clinical.staff.reallocation',
+ 'res_id': self.id,
+ 'view_mode': 'form',
+ 'target': 'new',
+ }
+
+ @api.multi
+ def batch_allocate(self):
+ self.write({'stage': 'batch_allocation'})
+ return {
+ 'type': 'ir.actions.act_window',
+ 'name': 'Nursing Re-Allocation',
+ 'res_model': 'nh.clinical.staff.reallocation',
+ 'res_id': self.id,
+ 'view_mode': 'form',
+ 'target': 'new',
+ }
+
+
+ @api.multi
+ def reallocate(self):
+ ResUsers = self.env['res.users']
+ wiz = self.read(['location_ids', 'user_ids'])[0]
location_ids = wiz.get('location_ids')
- loc_user_ids = self.get_users_for_locations(
- cr, uid, location_ids, context=context)
+ loc_user_ids = self.get_users_for_locations(location_ids)
user_ids = wiz.get('user_ids')
recompute = False
for u_id in loc_user_ids:
- if u_id not in user_ids and u_id != uid:
+ if u_id not in user_ids and u_id != self.env.uid:
recompute = True
- user = user_pool.read(
- cr, uid, u_id, ['location_ids'], context=context)
+ user = u_id.read(['location_ids'])[0]
uloc_ids = user.get('location_ids')
loc_ids = list_diff(uloc_ids, location_ids)
- self.responsibility_allocation_activity(
- cr, uid, u_id, loc_ids, context=context)
+ self.responsibility_allocation_activity(u_id.id, loc_ids)
# Remove patient followers
loc_ids = list_intersect(uloc_ids, location_ids)
- self.unfollow_patients_in_locations(
- cr, uid, loc_ids, context=context)
- self.write(cr, uid, ids, {'stage': 'allocation'}, context=context)
+ self.unfollow_patients_in_locations(loc_ids)
+ self.write({'stage': 'allocation'})
if recompute:
- allocating_ids = self._get_default_allocatings(cr, uid,
- context=context)
- self.write(cr, uid, ids,
- {'allocating_ids': [[6, 0, allocating_ids]]},
- context=context)
+ allocating_ids = self._get_default_allocatings()
+ self.write({'allocating_ids': [[6, 0, allocating_ids]]})
return {
'type': 'ir.actions.act_window',
'name': 'Nursing Re-Allocation',
'res_model': 'nh.clinical.staff.reallocation',
- 'res_id': ids,
+ 'res_id': self.id,
'view_mode': 'form',
'target': 'new',
}
- def complete(self, cr, uid, ids, context=None):
- if isinstance(ids, list):
- ids = ids[0]
- if not isinstance(ids, int):
- raise ValueError('Invalid ID passed to complete')
- allocating_pool = self.pool['nh.clinical.allocating']
- wizard = self.browse(cr, uid, ids, context=context)
+
+ @api.multi
+ def complete(self):
allocation = {
u.id: [l.id for l in u.location_ids if l.id not
- in wizard.location_ids.ids] for u in wizard.user_ids}
- for allocating in allocating_pool.browse(
- cr, uid, [a.id for a in wizard.allocating_ids],
- context=context):
+ in self.location_ids.ids] for u in self.user_ids}
+ for allocating in self.allocating_ids:
if allocating.nurse_id:
allocation[allocating.nurse_id.id].append(
allocating.location_id.id)
- if allocating.nurse_id.id == uid:
+ if allocating.nurse_id.id == self.env.uid:
allocation[allocating.nurse_id.id].append(
- wizard.ward_id.id)
+ self.ward_id.id)
for hca in allocating.hca_ids:
allocation[hca.id].append(allocating.location_id.id)
- if uid not in allocation:
- allocation[uid] = [wizard.ward_id.id]
- elif wizard.ward_id.id not in allocation.get(uid):
- allocation[uid].append(wizard.ward_id.id)
+ if self.env.uid not in allocation:
+ allocation[self.env.uid] = [self.ward_id.id]
+ elif self.ward_id.id not in allocation.get(self.env.uid):
+ allocation[self.env.uid].append(self.ward_id.id)
for key, value in allocation.iteritems():
- self.responsibility_allocation_activity(cr, uid, key, value,
- context=context)
+ self.responsibility_allocation_activity(key, value)
return {'type': 'ir.actions.act_window_close'}
-class doctor_allocation_wizard(osv.TransientModel):
+class doctor_allocation_wizard(models.TransientModel):
_name = 'nh.clinical.doctor.allocation'
_rec_name = 'create_uid'
@@ -391,62 +488,56 @@ class doctor_allocation_wizard(osv.TransientModel):
'NH Clinical Consultant Group',
'NH Clinical Registrar Group']
- def _get_default_ward(self, cr, uid, context=None):
- location_pool = self.pool['nh.clinical.location']
- ward_ids = location_pool.search(cr, uid, [['usage', '=', 'ward'],
- ['user_ids', 'in', [uid]]],
- context=context)
+ @api.multi
+ def _get_default_ward(self):
+ NhClinicalLocation = self.env['nh.clinical.location']
+ ward_ids = NhClinicalLocation.search([['usage', '=', 'ward'], ['user_ids', 'in', [self.env.uid]]])
if not ward_ids:
raise osv.except_osv(
'Shift Management Error!',
'You must be in charge of a ward to do this task!')
return ward_ids[0]
- def _get_default_locations(self, cr, uid, context=None):
- location_pool = self.pool['nh.clinical.location']
- ward_ids = location_pool.search(
- cr, uid, [['usage', '=', 'ward'], ['user_ids', 'in', [uid]]],
- context=context)
+ @api.multi
+ def _get_default_locations(self):
+ NhClinicalLocation = self.env['nh.clinical.location']
+ ward_ids = NhClinicalLocation.search([['usage', '=', 'ward'], ['user_ids', 'in', [self.env.uid]]])
if not ward_ids:
raise osv.except_osv(
'Shift Management Error!',
'You must be in charge of a ward to do this task!')
- location_ids = location_pool.search(
- cr, uid, [['id', 'child_of', ward_ids[0]]], context=context)
+ location_ids = NhClinicalLocation.search([['id', 'child_of', ward_ids.ids]])
return location_ids
- def _get_current_doctors(self, cr, uid, context=None):
- location_pool = self.pool['nh.clinical.location']
- user_pool = self.pool['res.users']
- ward_ids = location_pool.search(cr, uid, [['usage', '=', 'ward'],
- ['user_ids', 'in', [uid]]],
- context=context)
+ @api.multi
+ def _get_current_doctors(self):
+ NhClinicalLocation = self.env['nh.clinical.location']
+ ResUsers = self.env['res.users']
+ ward_ids = NhClinicalLocation.search([['usage', '=', 'ward'], ['user_ids', 'in', [self.env.uid]]])
if not ward_ids:
raise osv.except_osv(
'Shift Management Error!',
'You must be in charge of a ward to do this task!')
- doctor_ids = user_pool.search(
- cr, uid, [['groups_id.name', 'in', self._doctor_groups],
- ['location_ids', 'in', ward_ids]], context=context)
+ doctor_ids = ResUsers.search([['groups_id.name', 'in', self._doctor_groups], ['location_ids', 'in', ward_ids.ids]])
return doctor_ids
- _columns = {
- 'create_uid': fields.many2one('res.users',
- 'User Executing the Wizard'),
- 'create_date': fields.datetime('Create Date'),
- 'stage': fields.selection(_stages, string='Stage'),
- 'ward_id': fields.many2one('nh.clinical.location', string='Ward',
- domain=[['usage', '=', 'ward']]),
- 'doctor_ids': fields.many2many('res.users', 'docalloc_doc_rel',
- 'allocation_id', 'user_id',
- string='Current Doctors'),
- 'location_ids': fields.many2many('nh.clinical.location',
- 'docalloc_loc_rel', 'allocation_id',
- 'location_id', string='Locations'),
- 'user_ids': fields.many2many(
- 'res.users', 'docalloc_user_rel', 'allocation_id', 'user_id',
- string='Users', domain=[['groups_id.name', 'in', _doctor_groups]])
- }
+
+ create_uid = fields.Many2one('res.users',
+ 'User Executing the Wizard')
+ create_date = fields.Datetime('Create Date')
+ stage = fields.Selection(_stages, string='Stage')
+ ward_id = fields.Many2one('nh.clinical.location', string='Ward',
+ domain=[['usage', '=', 'ward']])
+ doctor_ids = fields.Many2many('res.users', 'docalloc_doc_rel',
+ 'allocation_id', 'user_id',
+ string='Current Doctors')
+ location_ids = fields.Many2many('nh.clinical.location',
+ 'docalloc_loc_rel', 'allocation_id',
+ 'location_id', string='Locations')
+ user_ids = fields.Many2many(
+ 'res.users', 'docalloc_user_rel', 'allocation_id', 'user_id',
+ string='Users', domain=[['groups_id.name', 'in', _doctor_groups]])
+
_defaults = {
'stage': 'review',
'ward_id': _get_default_ward,
@@ -454,80 +545,62 @@ def _get_current_doctors(self, cr, uid, context=None):
'doctor_ids': _get_current_doctors
}
- def deallocate(self, cr, uid, ids, context=None):
- if not isinstance(ids, list):
- ids = [ids]
- wiz = self.browse(cr, uid, ids[0], context=context)
- deallocate_location_ids = \
- [location.id for location in wiz.location_ids]
-
- user_pool = self.pool['res.users']
- all_doctor_ids = user_pool.search(
- cr, uid, [['groups_id.name', 'in', self._doctor_groups]],
- context=context
- )
+ @api.multi
+ def deallocate(self):
+ deallocate_location_ids = self.location_ids.ids
+
+ ResUsers = self.env['res.users']
+ all_doctors = ResUsers.search([['groups_id.name', 'in', self._doctor_groups]])
- for doctor_id in all_doctor_ids:
- doctor_current_location_ids = user_pool.read(
- cr, uid, doctor_id, fields=['location_ids']
- )['location_ids']
+ for doctor in all_doctors:
+ doctor_current_location_ids = doctor.location_ids.ids
doctor_new_location_ids = \
set(doctor_current_location_ids) - set(deallocate_location_ids)
- user_pool.write(
- cr, uid, doctor_id,
- {'location_ids': [(6, 0, doctor_new_location_ids)]},
- context=context
- )
+ doctor.write({'location_ids': [(6, 0, doctor_new_location_ids)]})
- self.write(cr, uid, ids, {'stage': 'users'}, context=context)
+ self.write({'stage': 'users'})
return {
'type': 'ir.actions.act_window',
'name': 'Medical Shift Change',
'res_model': 'nh.clinical.doctor.allocation',
- 'res_id': ids[0],
+ 'res_id': self.id,
'view_mode': 'form',
'target': 'new',
}
- def submit_users(self, cr, uid, ids, context=None):
- if not isinstance(ids, list):
- ids = [ids]
- wiz = self.browse(cr, uid, ids[0], context=context)
- respallocation_pool = self.pool[
+ @api.multi
+ def submit_users(self):
+ NhClinicalUserResponsibilityAllocation = self.env[
'nh.clinical.user.responsibility.allocation'
]
- activity_pool = self.pool['nh.activity']
- for doctor in wiz.user_ids:
- activity_id = respallocation_pool.create_activity(
- cr, uid, {}, {
- 'responsible_user_id': doctor.id,
- 'location_ids': [[6, 0, [wiz.ward_id.id]]]
- }, context=context)
- activity_pool.complete(cr, uid, activity_id, context=context)
+ NhActivity = self.env['nh.activity']
+ for doctor in self.user_ids:
+ activity = NhClinicalUserResponsibilityAllocation.create_activity({}, {
+ 'responsible_user_id': doctor.id,
+ 'location_ids': [[6, 0, [self.ward_id.id]]]
+ })
+ NhActivity.complete(activity)
return {'type': 'ir.actions.act_window_close'}
-
-class allocating_user(osv.TransientModel):
+class allocating_user(models.TransientModel):
_name = 'nh.clinical.allocating'
_rec_name = 'location_id'
- _columns = {
- 'location_id': fields.many2one('nh.clinical.location', 'Location',
- required=1),
- 'patient_ids': fields.related('location_id', 'patient_ids',
- type='many2many',
- relation='nh.clinical.patient',
- string='Patient'),
- 'nurse_id': fields.many2one(
- 'res.users', 'Responsible Nurse',
- domain=[['groups_id.name', 'in', ['NH Clinical Nurse Group']]]),
- 'hca_ids': fields.many2many(
- 'res.users', 'allocating_hca_rel', 'allocating_id', 'hca_id',
- string='Responsible HCAs',
- domain=[['groups_id.name', 'in', ['NH Clinical HCA Group']]]),
- 'nurse_name': fields.related('nurse_id', 'name', type='char', size=100,
- string='Responsible Nurse')
- }
+ selected = fields.Boolean(string="Batch")
+ location_id = fields.Many2one('nh.clinical.location', 'Location',
+ required=1)
+ patient_ids = fields.Many2many(related='location_id.patient_ids',
+ relation='nh.clinical.patient',
+ string='Patient')
+ nurse_id = fields.Many2one(
+ 'res.users', 'Responsible Nurse',
+ domain=[['groups_id.name', 'in', ['NH Clinical Nurse Group']]])
+ hca_ids = fields.Many2many(
+ 'res.users', 'allocating_hca_rel', 'allocating_id', 'hca_id',
+ string='Responsible HCAs',
+ domain=[['groups_id.name', 'in', ['NH Clinical HCA Group']]])
+ nurse_name = fields.Char(related='nurse_id.name', size=100, string='Responsible Nurse')
+
def fields_view_get(self, cr, uid, view_id=None, view_type='form',
context=None, toolbar=False, submenu=False):
@@ -575,28 +648,26 @@ def fields_view_get(self, cr, uid, view_id=None, view_type='form',
]
return res
-
-class user_allocation_wizard(osv.TransientModel):
+class user_allocation_wizard(models.TransientModel):
_name = 'nh.clinical.user.allocation'
_stages = [['wards', 'Select Wards'], ['users', 'Select Users'],
['allocation', 'Allocation']]
- _columns = {
- 'create_uid': fields.many2one('res.users',
- 'User Executing the Wizard'),
- 'stage': fields.selection(_stages, string='Stage'),
- 'ward_ids': fields.many2many('nh.clinical.location',
- 'allocation_ward_rel', 'allocation_id',
- 'location_id', string='Wards',
- domain=[['usage', '=', 'ward']]),
- 'user_ids': fields.many2many('res.users', 'allocation_user_rel',
- 'allocation_id', 'user_id',
- string='Users'),
- 'allocating_user_ids': fields.many2many(
- 'nh.clinical.allocating', 'allocating_allocation_rel',
- 'allocation_id', 'allocating_user_id', string='Allocating Users')
- }
+ create_uid = fields.Many2one('res.users',
+ 'User Executing the Wizard')
+ stage = fields.Selection(_stages, string='Stage')
+ ward_ids = fields.Many2many('nh.clinical.location',
+ 'allocation_ward_rel', 'allocation_id',
+ 'location_id', string='Wards',
+ domain=[['usage', '=', 'ward']])
+ user_ids = fields.Many2many('res.users', 'allocation_user_rel',
+ 'allocation_id', 'user_id',
+ string='Users')
+ allocating_user_ids = fields.Many2many(
+ 'nh.clinical.allocating', 'allocating_allocation_rel',
+ 'allocation_id', 'allocating_user_id', string='Allocating Users')
+
_defaults = {
'stage': 'users'
}
diff --git a/nh_clinical/wizard/user_allocation_view.xml b/nh_clinical/wizard/user_allocation_view.xml
index a4f2cc1c..66a05800 100644
--- a/nh_clinical/wizard/user_allocation_view.xml
+++ b/nh_clinical/wizard/user_allocation_view.xml
@@ -5,7 +5,7 @@
User Allocation Wizard Form
nh.clinical.user.allocation
-