102 lines
3.3 KiB
Python
102 lines
3.3 KiB
Python
import time
|
|
|
|
from datetime import datetime, timedelta
|
|
from netforce.model import Model, fields, get_model
|
|
from netforce.access import get_active_company
|
|
|
|
from . import utils
|
|
|
|
DRT=5
|
|
|
|
class ScheduleBoard(Model):
|
|
_name="clinic.schedule.board"
|
|
_string="Schedule Board"
|
|
_transient=True
|
|
|
|
_fields={
|
|
"date_from": fields.Date("From", required=True),
|
|
"date_to": fields.Date("To", required=True),
|
|
}
|
|
|
|
_defaults={
|
|
'date_from': lambda *a: time.strftime("%Y-%m-%d"),
|
|
'date_to': lambda *a: (datetime.now()+timedelta(days=DRT)).strftime("%Y-%m-%d"),
|
|
}
|
|
|
|
def get_report_data(self,ids,context={}):
|
|
company_id=get_active_company()
|
|
company=get_model("company").browse(company_id)
|
|
|
|
date_from=datetime.now().strftime("%Y-%m-%d")
|
|
date_to=(datetime.now()+timedelta(days=DRT)).strftime("%Y-%m-%d")
|
|
if ids:
|
|
obj=self.browse(ids)[0]
|
|
date_from=obj.date_from
|
|
date_to=obj.date_to
|
|
|
|
time_start='%s 00:00:00'%(date_from)
|
|
time_stop='%s 23:59:59'%(date_to)
|
|
|
|
dom=[]
|
|
dom.append(['time_start','>=','%s'%time_start])
|
|
dom.append(['time_stop','<=','%s'%time_stop])
|
|
|
|
lines=[]
|
|
empty_line={
|
|
'no': '',
|
|
'schedule_name': '',
|
|
'cycle_name': '',
|
|
'nurse_id': None,
|
|
'nurse_name': '',
|
|
'level_id': None,
|
|
'level_name': '',
|
|
'note':'',
|
|
'title':True,
|
|
'schedule_id': None,
|
|
}
|
|
|
|
for schedule in get_model("clinic.schedule").search_browse(dom):
|
|
no=1
|
|
line=empty_line.copy()
|
|
date=schedule.date
|
|
line['schedule_id']=schedule.id
|
|
line['schedule_name']=utils.date2thai(date,format='%(Td)s %(d)s %(Tm)s',lang="th_TH2")
|
|
lines.append(line)
|
|
for line in schedule.lines:
|
|
nurse=line.nurse_id
|
|
level=line.level_id
|
|
cycle=line.cycle_id
|
|
line={
|
|
'no': no,
|
|
'cycle_id': cycle.id,
|
|
'cycle_name': cycle.name or '',
|
|
'cycle_color': cycle.color or '',
|
|
'nurse_id': nurse.id,
|
|
'nurse_name': nurse.name or "",
|
|
'level_id': level.id,
|
|
'level_name': level.name or "",
|
|
'title': False,
|
|
'schedule_id': None,
|
|
'schedule_name': '',
|
|
'note': line.note or "",
|
|
}
|
|
lines.append(line)
|
|
no+=1
|
|
has_duration=False
|
|
if date_from != date_to:
|
|
has_duration=True
|
|
date=utils.date2thai(date_from,format='ประจำวัน%(Td)s ที่ %(d)s %(Tm)s %(BY)s')
|
|
data={
|
|
'lines': lines,
|
|
'date': date,
|
|
'company_name': company.name,
|
|
'company_parent_name': company.parent_id.name,
|
|
'has_duration': has_duration,
|
|
'date_from': utils.date2thai(date_from,format='%(d)s %(Tm)s %(By)s',lang="th_TH2"),
|
|
'date_to': utils.date2thai(date_to,format='%(d)s %(Tm)s %(By)s',lang="th_TH2"),
|
|
}
|
|
|
|
return data
|
|
|
|
ScheduleBoard.register()
|