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"),
|
|
|
|
'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)
|
|
|
|
|
|
|
|
_defaults={
|
|
|
|
'cycle_item_id': _get_cycle_item_id,
|
|
|
|
'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=[]
|
|
|
|
if obj.choice=='item':
|
|
|
|
for line in obj.item_copy_id.lines:
|
|
|
|
nr=line.nurse_id
|
|
|
|
lines.append(('create', {
|
|
|
|
'nurse_id': nr.id,
|
|
|
|
'level_id': nr.level_id.id,
|
|
|
|
'state': nr.state,
|
|
|
|
}))
|
|
|
|
elif obj.choice=='schd':
|
|
|
|
for line in obj.schd_copy_id.lines:
|
|
|
|
nr=line.nurse_id
|
|
|
|
cycle=line.cycle_id
|
|
|
|
if item.cycle_id.id==cycle.id:
|
|
|
|
lines.append(('create', {
|
|
|
|
'nurse_id': nr.id,
|
|
|
|
'level_id': nr.level_id.id,
|
|
|
|
'state': nr.state,
|
|
|
|
}))
|
|
|
|
else:
|
|
|
|
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,
|
|
|
|
}))
|
|
|
|
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()
|