xxx
parent
d3e7066fdd
commit
136067e422
|
@ -3,6 +3,7 @@
|
|||
<field name="state"/>
|
||||
<button string="Options" dropdown="1">
|
||||
<item string="Copy" method="copy"/>
|
||||
<item string="Copy Nurses To Cycle Item" method="copy_nurses"/>
|
||||
<item string="View Cycle Item" method="view_cycle_item"/>
|
||||
</button>
|
||||
</head>
|
||||
|
|
|
@ -15,9 +15,20 @@ class Schedule(Model):
|
|||
res[obj.id]='%s, Nurse: %s'%(obj.cycle_id.name or "", total_nurse)
|
||||
return res
|
||||
|
||||
def _get_item(self,ids,context={}):
|
||||
res={}
|
||||
for obj in self.browse(ids):
|
||||
item_ids=get_model("clinic.cycle.item").search([['cycle_id','=',obj.cycle_id.id],['date','=',obj.time_start[0:10]]])
|
||||
item_id=None
|
||||
if item_ids:
|
||||
item_id=item_ids[0]
|
||||
res[obj.id]=item_id
|
||||
return res
|
||||
|
||||
_fields={
|
||||
"name": fields.Char("Name",function="_get_name"),
|
||||
'cycle_id': fields.Many2One("clinic.cycle","Cycle",required=True),
|
||||
'cycle_item_id': fields.Many2One("clinic.cycle.item","Cycle Item", function="_get_item"),
|
||||
"time_start": fields.DateTime("Time Start",required=True),
|
||||
"time_stop": fields.DateTime("Time Stop",required=True),
|
||||
'company_id': fields.Many2One("company","Company"),
|
||||
|
@ -45,9 +56,52 @@ class Schedule(Model):
|
|||
})
|
||||
|
||||
|
||||
def copy(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
nurse_ids=[nurse.id for nurse in obj.nurses]
|
||||
vals={
|
||||
'cycle_id': obj.cycle_id.id,
|
||||
'time_start': obj.time_start,
|
||||
'time_stop': obj.time_stop,
|
||||
'nurses': [('add', nurse_ids)],
|
||||
}
|
||||
obj_id=get_model("clinic.schedule").create(vals)
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_schedule',
|
||||
'mode': 'form',
|
||||
'active_id': obj_id,
|
||||
},
|
||||
'flash': 'Copy schedule successfully',
|
||||
}
|
||||
|
||||
def copy_nurses(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
nurses=[]
|
||||
for nurse in obj.nurses:
|
||||
nurses.append(('create',{
|
||||
'nurse_id': nurse.id,
|
||||
'level_id': nurse.level_id.id,
|
||||
}))
|
||||
|
||||
for nurse in obj.cycle_item_id.nurses:
|
||||
nurse.delete()
|
||||
|
||||
obj.cycle_item_id.write({
|
||||
'nurses': nurses,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_cycle_item',
|
||||
'mode': 'form',
|
||||
'active_id': obj.cycle_item_id.id,
|
||||
},
|
||||
'flash': 'Copy nurses to cycle item successfully',
|
||||
}
|
||||
|
||||
def view_cycle_item(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
item_id=get_model("clinic.cycle.item").search([['cycle_id','=',obj.cycle_id.id],['date','=',obj.time_start[0:10]]])
|
||||
item_id=obj.cycle_item_id.id
|
||||
msg=''
|
||||
if not item_id:
|
||||
# XXX
|
||||
|
@ -73,5 +127,4 @@ class Schedule(Model):
|
|||
'flash': msg,
|
||||
}
|
||||
|
||||
|
||||
Schedule.register()
|
||||
|
|
Loading…
Reference in New Issue