2014-11-03 11:22:48 +00:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
2014-11-11 00:51:44 +00:00
|
|
|
from netforce.model import Model, fields, get_model
|
2014-11-14 01:58:12 +00:00
|
|
|
from netforce.access import get_active_company, get_active_user
|
2014-10-28 15:16:16 +00:00
|
|
|
|
|
|
|
class Schedule(Model):
|
|
|
|
_name="clinic.schedule"
|
2014-11-05 07:10:03 +00:00
|
|
|
_string="Schedule"
|
2014-11-14 01:58:12 +00:00
|
|
|
_field_name="date"
|
2014-10-28 15:16:16 +00:00
|
|
|
|
|
|
|
def _get_name(self,ids,context={}):
|
|
|
|
res={}
|
|
|
|
for obj in self.browse(ids):
|
2014-11-17 00:59:19 +00:00
|
|
|
res[obj.id]='%s'%(obj.date)
|
2014-10-28 15:16:16 +00:00
|
|
|
return res
|
|
|
|
|
2014-11-11 01:35:53 +00:00
|
|
|
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
|
|
|
|
|
2014-10-28 15:16:16 +00:00
|
|
|
_fields={
|
2014-11-14 01:58:12 +00:00
|
|
|
'name': fields.Char("Name", function="_get_name"),
|
2014-11-11 01:35:53 +00:00
|
|
|
'cycle_item_id': fields.Many2One("clinic.cycle.item","Cycle Item", function="_get_item"),
|
2014-10-28 15:16:16 +00:00
|
|
|
"time_start": fields.DateTime("Time Start",required=True),
|
|
|
|
"time_stop": fields.DateTime("Time Stop",required=True),
|
2014-11-17 00:59:19 +00:00
|
|
|
'date': fields.Date("Date",required=True,search=True),
|
2014-11-14 01:58:12 +00:00
|
|
|
'lines': fields.One2Many("clinic.schedule.line","schedule_id","Lines"),
|
2014-10-28 15:16:16 +00:00
|
|
|
'company_id': fields.Many2One("company","Company"),
|
2014-11-17 00:59:19 +00:00
|
|
|
'state': fields.Selection([['draft','Draft'],['confirmed', 'Confirmed']],'State',search=True),
|
|
|
|
'user_id': fields.Many2One("base.user","Confirm By"),
|
2014-10-28 15:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_defaults={
|
2014-11-14 01:58:12 +00:00
|
|
|
'user_id': lambda *a: get_active_user(),
|
2014-10-28 15:16:16 +00:00
|
|
|
"company_id": lambda *a: get_active_company(),
|
2014-11-14 01:58:12 +00:00
|
|
|
'date': lambda *a: datetime.now().strftime("%Y-%m-%d"),
|
2014-11-03 11:22:48 +00:00
|
|
|
'time_start': lambda *a: datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
'time_stop': lambda *a: (datetime.now()+timedelta(seconds=3600)).strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
'state': 'draft',
|
2014-10-28 15:16:16 +00:00
|
|
|
}
|
2014-11-01 17:30:48 +00:00
|
|
|
|
2014-11-17 00:59:19 +00:00
|
|
|
_order="date desc"
|
|
|
|
|
2014-11-14 01:58:12 +00:00
|
|
|
_sql_constraints=[
|
|
|
|
('schedule_uniq','unique (date,company_id)','Date should be unique'),
|
|
|
|
]
|
|
|
|
|
2014-11-01 06:04:30 +00:00
|
|
|
def confirm(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write({
|
|
|
|
'state': 'confirmed',
|
|
|
|
})
|
|
|
|
|
|
|
|
def to_draft(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write({
|
|
|
|
'state': 'draft',
|
|
|
|
})
|
|
|
|
|
2014-11-11 00:51:44 +00:00
|
|
|
|
2014-11-11 01:35:53 +00:00
|
|
|
def copy(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
2014-11-17 00:59:19 +00:00
|
|
|
datenow=datetime.now().strftime("%Y-%m-%d")
|
|
|
|
old_ids=get_model('clinic.schedule').search([['date','=',datenow]])
|
|
|
|
if old_ids:
|
|
|
|
raise Exception("This schedule is already create!")
|
2014-11-11 01:35:53 +00:00
|
|
|
vals={
|
2014-11-14 01:58:12 +00:00
|
|
|
'lines': [],
|
2014-11-11 01:35:53 +00:00
|
|
|
}
|
2014-11-14 01:58:12 +00:00
|
|
|
for line in obj.lines:
|
|
|
|
vals['lines'].append(('create', {
|
|
|
|
'nurse_id': line.nurse_id.id,
|
|
|
|
'cycle_id': line.cycle_id.id
|
|
|
|
}
|
|
|
|
))
|
|
|
|
new_id=get_model("clinic.schedule").create(vals)
|
|
|
|
new_obj=get_model("clinic.schedule").browse(new_id)
|
2014-11-11 01:35:53 +00:00
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'name': 'clinic_schedule',
|
|
|
|
'mode': 'form',
|
2014-11-14 01:58:12 +00:00
|
|
|
'active_id': new_id,
|
2014-11-11 01:35:53 +00:00
|
|
|
},
|
2014-11-14 01:58:12 +00:00
|
|
|
'flash': 'Copy schedule from %s to %s successfully'%(obj.date,new_obj.date)
|
2014-11-11 01:35:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 01:58:12 +00:00
|
|
|
def copy2cycle_item(self,ids,context={}):
|
2014-11-11 01:35:53 +00:00
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
nurses=[]
|
2014-11-14 01:58:12 +00:00
|
|
|
for line in obj.lines:
|
|
|
|
nurse=line.nurse_id
|
2014-11-11 01:35:53 +00:00
|
|
|
nurses.append(('create',{
|
|
|
|
'nurse_id': nurse.id,
|
|
|
|
'level_id': nurse.level_id.id,
|
|
|
|
}))
|
2014-11-17 00:59:19 +00:00
|
|
|
print('xx')
|
2014-11-11 01:35:53 +00:00
|
|
|
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',
|
|
|
|
}
|
|
|
|
|
2014-11-14 01:58:12 +00:00
|
|
|
def onchange_date(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
date=data['date']
|
|
|
|
time_start=data['time_start'][11:]
|
|
|
|
data['time_start']='%s %s'%(date,time_start)
|
|
|
|
time_stop=data['time_stop'][11:]
|
|
|
|
data['time_stop']='%s %s'%(date,time_stop)
|
|
|
|
return data
|
|
|
|
|
|
|
|
def load_all_nurse(self,ids,context={}):
|
|
|
|
nurses=get_model("clinic.personal").search_browse([['type','=','nurse']])
|
|
|
|
vals={
|
|
|
|
'lines': [],
|
|
|
|
}
|
|
|
|
for nurse in nurses:
|
|
|
|
vals['lines'].append({
|
|
|
|
'cycle_id': nurse.id,
|
|
|
|
'nurse_id': nurse.id,
|
2014-11-11 00:51:44 +00:00
|
|
|
})
|
2014-11-14 01:58:12 +00:00
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write(vals)
|
|
|
|
|
|
|
|
def clear(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
for line in obj.lines:
|
|
|
|
line.delete()
|
2014-11-11 00:51:44 +00:00
|
|
|
return {
|
|
|
|
'next': {
|
2014-11-14 01:58:12 +00:00
|
|
|
'name': 'clinic_schedule',
|
2014-11-11 00:51:44 +00:00
|
|
|
'mode': 'form',
|
2014-11-14 01:58:12 +00:00
|
|
|
'active_id': obj.id,
|
2014-11-11 00:51:44 +00:00
|
|
|
},
|
2014-11-14 01:58:12 +00:00
|
|
|
'flash': 'List of nurse has been cleared.',
|
2014-11-11 00:51:44 +00:00
|
|
|
}
|
|
|
|
|
2014-10-28 15:16:16 +00:00
|
|
|
Schedule.register()
|
2014-11-14 01:58:12 +00:00
|
|
|
|