2015-01-22 01:34:22 +00:00
|
|
|
from netforce.model import Model, fields, get_model
|
|
|
|
|
|
|
|
class CycleItemCopy(Model):
|
|
|
|
_name="clinic.cycle.item.copy"
|
|
|
|
_transient=True
|
|
|
|
|
|
|
|
_fields={
|
|
|
|
"cycle_item_id": fields.Many2One("clinic.cycle.item","Cycle Item",required=True,on_delete="cascade"),
|
|
|
|
'choice': fields.Selection([['item','Cycle Item'],['schd','Schedule']],'Choice'),
|
|
|
|
"item_copy_id": fields.Many2One("clinic.cycle.item","Cycle Item"),
|
|
|
|
"schd_copy_id": fields.Many2One("clinic.schedule","Schedule"),
|
2015-01-22 08:07:22 +00:00
|
|
|
'department_id': fields.Many2One("clinic.department","Department"),
|
2015-01-22 01:34:22 +00:00
|
|
|
'lines': fields.One2Many("clinic.cycle.item.copy.line","item_copy_id","Lines"),
|
|
|
|
}
|
|
|
|
|
|
|
|
def _get_cycle_item_id(self,context={}):
|
|
|
|
refer_id=context.get("refer_id")
|
|
|
|
if not refer_id:
|
|
|
|
return None
|
|
|
|
return int(refer_id)
|
|
|
|
|
2015-01-22 08:07:22 +00:00
|
|
|
def _get_department(self,context={}):
|
|
|
|
refer_id=context.get("refer_id")
|
|
|
|
if not refer_id:
|
|
|
|
return None
|
|
|
|
item=get_model('clinic.cycle.item').browse(int(refer_id))
|
|
|
|
dpt=item.department_id
|
|
|
|
print('dpt ', dpt.id)
|
|
|
|
return dpt.id
|
|
|
|
|
2015-01-22 01:34:22 +00:00
|
|
|
_defaults={
|
|
|
|
'cycle_item_id': _get_cycle_item_id,
|
2015-01-22 08:07:22 +00:00
|
|
|
'department_id': _get_department,
|
2015-01-22 01:34:22 +00:00
|
|
|
'choice': 'item',
|
|
|
|
}
|
|
|
|
|
2015-01-22 07:20:04 +00:00
|
|
|
def update_line(self,context={}):
|
2015-01-22 01:34:22 +00:00
|
|
|
data=context['data']
|
2015-01-22 07:20:04 +00:00
|
|
|
lines=[]
|
|
|
|
if data['choice']=='item':
|
|
|
|
item=get_model("clinic.cycle.item").browse(data['item_copy_id'])
|
|
|
|
for line in item.lines:
|
|
|
|
nr=line.nurse_id
|
|
|
|
dpt=nr.department_id
|
|
|
|
lines.append({
|
|
|
|
'nurse_id':nr.id,
|
|
|
|
'department_id': dpt.id,
|
|
|
|
})
|
|
|
|
elif data['choice']=='schd':
|
|
|
|
item=get_model("clinic.cycle.item").browse(data['cycle_item_id'])
|
|
|
|
schd=get_model("clinic.schedule").browse(data['schd_copy_id'])
|
|
|
|
cycle=item.cycle_id
|
|
|
|
for line in schd.lines:
|
|
|
|
nr=line.nurse_id
|
|
|
|
dpt=nr.department_id
|
|
|
|
if cycle.id==line.cycle_id.id:
|
|
|
|
lines.append({
|
|
|
|
'nurse_id':nr.id,
|
|
|
|
'department_id': dpt.id,
|
|
|
|
})
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
return lines
|
2015-01-22 01:34:22 +00:00
|
|
|
|
2015-01-22 07:20:04 +00:00
|
|
|
def onchange_choice(self,context={}):
|
2015-01-22 01:34:22 +00:00
|
|
|
data=context['data']
|
2015-01-22 07:20:04 +00:00
|
|
|
if data['choice']:
|
|
|
|
data['lines']=self.update_line(context=context)
|
2015-01-22 01:34:22 +00:00
|
|
|
return data
|
|
|
|
|
2015-01-22 07:20:04 +00:00
|
|
|
def onchange_item(self,context={}):
|
2015-01-22 01:34:22 +00:00
|
|
|
data=context['data']
|
2015-01-22 07:20:04 +00:00
|
|
|
data['lines']=self.update_line(context=context)
|
|
|
|
return data
|
|
|
|
|
|
|
|
def load(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
item=obj.cycle_item_id
|
|
|
|
for line in item.lines:
|
|
|
|
line.delete()
|
|
|
|
lines=[]
|
2015-01-23 09:41:12 +00:00
|
|
|
for line in obj.lines:
|
|
|
|
nr=line.nurse_id
|
|
|
|
lines.append(('create', {
|
|
|
|
'nurse_id': nr.id,
|
|
|
|
'level_id': nr.level_id.id,
|
|
|
|
'state': nr.state,
|
|
|
|
}))
|
2015-01-22 07:20:04 +00:00
|
|
|
item.write({
|
|
|
|
'lines': lines,
|
|
|
|
})
|
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'name': 'clinic_cycle_item',
|
|
|
|
'mode': 'form',
|
|
|
|
'active_id': item.id,
|
|
|
|
},
|
|
|
|
'flash': 'Load Nurse Complete!',
|
|
|
|
}
|
2015-01-22 01:34:22 +00:00
|
|
|
|
|
|
|
CycleItemCopy.register()
|