diff --git a/netforce_clinic/layouts/clinic_cycle_item_copy.xml b/netforce_clinic/layouts/clinic_cycle_item_copy.xml
index c024ebf..1c15e80 100644
--- a/netforce_clinic/layouts/clinic_cycle_item_copy.xml
+++ b/netforce_clinic/layouts/clinic_cycle_item_copy.xml
@@ -1,16 +1,17 @@
-
diff --git a/netforce_clinic/layouts/clinic_cycle_item_form.xml b/netforce_clinic/layouts/clinic_cycle_item_form.xml
index 467dc61..7fc78b6 100644
--- a/netforce_clinic/layouts/clinic_cycle_item_form.xml
+++ b/netforce_clinic/layouts/clinic_cycle_item_form.xml
@@ -3,8 +3,8 @@
@@ -22,6 +22,7 @@
+
diff --git a/netforce_clinic/layouts/clinic_schedule_form.xml b/netforce_clinic/layouts/clinic_schedule_form.xml
index ecd67f2..5cb480a 100644
--- a/netforce_clinic/layouts/clinic_schedule_form.xml
+++ b/netforce_clinic/layouts/clinic_schedule_form.xml
@@ -4,7 +4,7 @@
@@ -12,12 +12,12 @@
-
-
+
+
-
+
diff --git a/netforce_clinic/layouts/clinic_visit_board.xml b/netforce_clinic/layouts/clinic_visit_board.xml
index e401db7..24374c7 100644
--- a/netforce_clinic/layouts/clinic_visit_board.xml
+++ b/netforce_clinic/layouts/clinic_visit_board.xml
@@ -1,12 +1,12 @@
diff --git a/netforce_clinic/models/cycle_item_copy.py b/netforce_clinic/models/cycle_item_copy.py
index f0f6cfe..580e8c4 100644
--- a/netforce_clinic/models/cycle_item_copy.py
+++ b/netforce_clinic/models/cycle_item_copy.py
@@ -23,16 +23,87 @@ class CycleItemCopy(Model):
'choice': 'item',
}
+ def update_line(self,context={}):
+ data=context['data']
+ 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
+
def onchange_choice(self,context={}):
data=context['data']
+ if data['choice']:
+ data['lines']=self.update_line(context=context)
return data
def onchange_item(self,context={}):
data=context['data']
- return data
-
- def onchange_schd(self,context={}):
- data=context['data']
- return data
+ 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!',
+ }
CycleItemCopy.register()
diff --git a/netforce_clinic/models/cycle_item_copy_line.py b/netforce_clinic/models/cycle_item_copy_line.py
index 3845ee9..83d0901 100644
--- a/netforce_clinic/models/cycle_item_copy_line.py
+++ b/netforce_clinic/models/cycle_item_copy_line.py
@@ -7,6 +7,7 @@ class CycleItemCopyLine(Model):
_fields={
"item_copy_id": fields.Many2One("clinic.cycle.item.copy","Copy Item",required=True,on_delete="cascade"),
'nurse_id': fields.Many2One("clinic.staff","Nurse",domain=[['type','=','nurse']]),
+ 'department_id': fields.Many2One("clinic.department","Department"),
}
diff --git a/netforce_clinic/models/cycle_item_line.py b/netforce_clinic/models/cycle_item_line.py
index 1d9bf8f..b467f40 100644
--- a/netforce_clinic/models/cycle_item_line.py
+++ b/netforce_clinic/models/cycle_item_line.py
@@ -9,6 +9,7 @@ class CycleItemLine(Model):
'level_id': fields.Many2One("clinic.staff.level", "Level",),
'nurse_id': fields.Many2One("clinic.staff",'Nurse',domain=[['type','=','nurse']]),
'department_id': fields.Many2One("clinic.department","Department"),
+ "state": fields.Selection([["part_time","Part Time"],["full_time","Full Time"]],"Working Status",search=True),
}
CycleItemLine.register()
diff --git a/netforce_clinic/models/schedule.py b/netforce_clinic/models/schedule.py
index 7def79c..359467f 100644
--- a/netforce_clinic/models/schedule.py
+++ b/netforce_clinic/models/schedule.py
@@ -7,38 +7,20 @@ from netforce.utils import get_data_path
class Schedule(Model):
_name="clinic.schedule"
_string="Schedule"
- _field_name="date"
+ _name_field="name"
_key=['name']
def _get_name(self,ids,context={}):
res={}
for obj in self.browse(ids):
- st="\n" # XXX
- count=0
- for line in obj.lines:
- nurse=line.nurse_id
- level=line.level_id
- cycle=line.cycle_id
- st+='#%s %s %s\n'%(cycle.sequence,nurse.name,level.name or "")
- count+=1
- res[obj.id]='%s'%(st if count else 'No nurse')
+ count=len(obj.lines)
+ dpt=obj.department_id
+ name='%s %s'%(obj.date, dpt.name or '')
+ res[obj.id]='%s'%(name if count else 'Waiting planing')
return res
-
- def _get_item(self,ids,context={}):
- res={}
- for obj in self.browse(ids):
- cycle_id=None
- if obj.cycle_id:
- cycle_id=obj.cycle_id.id
- item_ids=get_model("clinic.cycle.item").search([['cycle_id','=',cycle_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"),
+ 'name': fields.Char("Name", function="_get_name",store=True),
"time_start": fields.DateTime("Time Start",required=True),
"time_stop": fields.DateTime("Time Stop",required=True),
'date': fields.Date("Date",required=True,search=True),
@@ -244,6 +226,19 @@ class Schedule(Model):
nurse=get_model("clinic.staff").browse(nurse_id)
line['level_id']=nurse.level_id.id
return data
+
+ def create(self,vals,**kw):
+ id=super().create(vals,**kw)
+ self.function_store([id])
+
+ def write(self,ids,vals,**kw):
+ super().write(ids,vals,**kw)
+ self.function_store(ids)
+
+ def onchange_branch(self,context={}):
+ data=context['data']
+ data['department_id']=None
+ return data
Schedule.register()
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index 1f8aa91..cbb7054 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -91,56 +91,12 @@ class ClinicSetting(Model):
return True
def run_script(self,ids,context={}):
- db=get_connection()
- db.execute("""
- update clinic_branch set active=True;
- update clinic_department set active=True;
- """)
- print("Done!")
- return
-
- obj=self.browse(ids)[0]
- ################ update sickbed #############
- #sickbed: update department
- for sb in get_model('clinic.sickbed').search_browse([]):
- hdcs=sorted(sb.hd_cases, key=lambda a: a.id)
- if hdcs:
- hdc=hdcs[0]
- #patient=hdc.patient_id
- sb.write({
- 'department_id': hdc.department_id.id,
+ for item in get_model("clinic.cycle.item").search_browse([]):
+ for line in item.lines:
+ nr=line.nurse_id
+ line.write({
+ 'state': nr.state,
})
- #print("Done!")
- #return
-
- #############################################
-
- ############### cycle item
- for lc in get_model('clinic.labor.cost').search_browse([]):
- lc.delete()
-
- db=get_connection()
- res=db.query("""
- select cycle_item_id, nurse_id, level_id from clinic_cycle_item_nurse
- """)
- for rs in res:
- item_id=rs['cycle_item_id']
- nid=rs['nurse_id']
- lid=rs['level_id']
- if item_id:
- item=get_model('clinic.cycle.item').browse(item_id)
- item.write({
- 'lines': [('create',{'nurse_id': nid, 'level_id': lid})],
- })
- print('update ', item.name)
- item.validate()
- if item.department_id:
- print("update department for nurse", nid)
- get_model("clinic.staff").browse(nid).write({
- 'department_id': item.department_id.id,
- })
- #return
- #############################################
print("Done!")
def reset_last_import(self,ids,context={}):
diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py
index 924fc6b..8b2e82f 100644
--- a/netforce_clinic/models/visit.py
+++ b/netforce_clinic/models/visit.py
@@ -218,6 +218,10 @@ class Visit(Model):
def get_schedule(date):
dom=[]
dom.append(['date','=',date])
+ if branch:
+ dom.append(['branch_id','=',branch.id])
+ if department:
+ dom.append(['department_id','=',department.id])
schedule=None
schedules=get_model("clinic.schedule").search_browse(dom)
if schedules:
@@ -239,14 +243,10 @@ class Visit(Model):
# clear old nurse in cycle item
item_id=item_ids[0]
item=item_obj.browse(item_id)
- if item.state!='draft':
- # reset nurse
- for nurse in item.lines:
- nurse.delete()
- # copy nurse from schedule
+ # copy nurse from schedule(only draft)
item=item_obj.browse(item_id)
- if item.state!='draft':
+ if not item.lines and item.state=='draft':
schedule=get_schedule(date)
if schedule:
for line in schedule.lines:
@@ -255,9 +255,32 @@ class Visit(Model):
item_vals['lines'].append(('create',{
'nurse_id': nurse.id,
'level_id': nurse.level_id.id,
+ 'state': nurse.state,
}))
item.write(item_vals)
+ # copy nurse from previous cycle item
+ if not item.lines:
+ dom=[
+ ['branch_id','=',branch.id],
+ ['department_id','=',department.id],
+ ]
+ for item2 in get_model("clinic.cycle.item").search_browse([]):
+ lines=[]
+ for line in item2.lines:
+ nr=line.nurse_id
+ lines.append(('create', {
+ 'nurse_id': nr.id,
+ 'level_id': nr.level_id.id,
+ 'state': nr.state,
+ }))
+ if lines:
+ print("copy nurse from %s to %s"%(item2.name, item.name))
+ item.write({
+ 'lines': lines,
+ })
+ break
+
obj.write({
'cycle_item_id': item_id,
})
diff --git a/netforce_clinic/models/visit_board.py b/netforce_clinic/models/visit_board.py
index b3879c6..f2f59b1 100644
--- a/netforce_clinic/models/visit_board.py
+++ b/netforce_clinic/models/visit_board.py
@@ -318,7 +318,17 @@ class VisitBoard(Model):
data['date_from']="%s-%s-01"%(year,month)
data['date_to']="%s-%s-%s"%(year,month,total_day)
return data
-
+
+ def onchange_datefrom(self,context={}):
+ data=context['data']
+ data['date_to']=data['date_from']
+ return data
+
+ def onchange_branch(self,context={}):
+ data=context['data']
+ data['department_id']=None
+ return data
+
def confirm(self,ids,context={}):
obj=self.browse(ids)[0]
return {
@@ -327,5 +337,5 @@ class VisitBoard(Model):
'name': 'clinic_popup_visit_confirm',
}
}
-
+
VisitBoard.register()
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt
index 1c52e06..32076ac 100644
--- a/netforce_clinic/todo.txt
+++ b/netforce_clinic/todo.txt
@@ -5,7 +5,7 @@ todo:
- popup messagging -> Ask DJ
- modify message of log -> Ask DJ
- show image of staff
- - copy old nurse from previous cycle item
+ - copy old nurse from previous cycle item -> fixing
- multi confirm on visit board **** -> ok
=======
generate visit ใหม่ -> ok