diff --git a/netforce_clinic/actions/clinic_load_nurses.xml b/netforce_clinic/actions/clinic_load_nurses.xml
new file mode 100644
index 0000000..355d974
--- /dev/null
+++ b/netforce_clinic/actions/clinic_load_nurses.xml
@@ -0,0 +1,6 @@
+
+ List Nurse
+ form_popup
+ clinic.schedule.load.nurse
+ _popup
+
diff --git a/netforce_clinic/actions/clinic_schedule.xml b/netforce_clinic/actions/clinic_schedule.xml
index 2b0b1b1..896ef03 100644
--- a/netforce_clinic/actions/clinic_schedule.xml
+++ b/netforce_clinic/actions/clinic_schedule.xml
@@ -2,7 +2,7 @@
Schedules
multi_view
clinic.schedule
- calendar,list,page,form
+ list,page,form,calendar
[["All",[]],["Draft",[["state","=","draft"]]],["Confirmed",[["state","=","confirmed"]]]]
clinic_menu
diff --git a/netforce_clinic/layouts/clinic_hd_case_form.xml b/netforce_clinic/layouts/clinic_hd_case_form.xml
index d852095..dd05b15 100644
--- a/netforce_clinic/layouts/clinic_hd_case_form.xml
+++ b/netforce_clinic/layouts/clinic_hd_case_form.xml
@@ -108,7 +108,6 @@
-
diff --git a/netforce_clinic/layouts/clinic_load_nurse_form.xml b/netforce_clinic/layouts/clinic_load_nurse_form.xml
new file mode 100644
index 0000000..dfdfd3e
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_load_nurse_form.xml
@@ -0,0 +1,15 @@
+
diff --git a/netforce_clinic/layouts/clinic_personal_form.xml b/netforce_clinic/layouts/clinic_personal_form.xml
index df06a20..9379ab7 100644
--- a/netforce_clinic/layouts/clinic_personal_form.xml
+++ b/netforce_clinic/layouts/clinic_personal_form.xml
@@ -15,11 +15,11 @@
-
+
+
-
@@ -39,17 +39,7 @@
-
-
-
-
-
-
-
-
-
-
-
+
@@ -57,6 +47,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/netforce_clinic/layouts/clinic_schedule_calendar.xml b/netforce_clinic/layouts/clinic_schedule_calendar.xml
index 04b312d..01fb5ad 100644
--- a/netforce_clinic/layouts/clinic_schedule_calendar.xml
+++ b/netforce_clinic/layouts/clinic_schedule_calendar.xml
@@ -1,4 +1,4 @@
-
+
diff --git a/netforce_clinic/layouts/clinic_schedule_form.xml b/netforce_clinic/layouts/clinic_schedule_form.xml
index 5c6880b..2a78182 100644
--- a/netforce_clinic/layouts/clinic_schedule_form.xml
+++ b/netforce_clinic/layouts/clinic_schedule_form.xml
@@ -3,19 +3,35 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
diff --git a/netforce_clinic/layouts/clinic_schedule_list.xml b/netforce_clinic/layouts/clinic_schedule_list.xml
index fe0c16c..565d306 100644
--- a/netforce_clinic/layouts/clinic_schedule_list.xml
+++ b/netforce_clinic/layouts/clinic_schedule_list.xml
@@ -1,6 +1,4 @@
-
-
-
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index 284b0c5..89d6e5a 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -48,4 +48,8 @@ from . import personal
from . import personal_categ
from . import personal_level
from . import personal_move
+from . import personal_cycle
from . import schedule
+from . import schedule_line
+from . import load_nurse
+from . import load_nurse_line
diff --git a/netforce_clinic/models/gen_visit.py b/netforce_clinic/models/gen_visit.py
index 08126a8..d0597ae 100644
--- a/netforce_clinic/models/gen_visit.py
+++ b/netforce_clinic/models/gen_visit.py
@@ -197,17 +197,17 @@ class GenVisit(Model):
for vals in visit_vals:
vals['nurse_vals']=nurse_vals # XXX
visit_obj.create(vals)
- dom=[]
- dom.append(['time_start','>=','%s %s'%(obj.date_from[0:10],' 00:00:00')])
- dom.append(['time_stop','<=','%s %s'%(start_date.strftime(FMT_DATE)[0:10],' 23:59:59')])
- dom.append(['cycle_id','=',obj.cycle_id.id])
- schedule_obj=get_model("clinic.schedule")
- schedule_ids=schedule_obj.search(dom)
- schedule_obj.delete(schedule_ids)
- nurse_ids=[nurse['id'] for nurse in nurse_vals]
- for key, vals in schedules.items():
- vals['nurses']=[('add', nurse_ids)]
- schedule_obj.create(vals)
+ #dom=[]
+ #dom.append(['time_start','>=','%s %s'%(obj.date_from[0:10],' 00:00:00')])
+ #dom.append(['time_stop','<=','%s %s'%(start_date.strftime(FMT_DATE)[0:10],' 23:59:59')])
+ #dom.append(['cycle_id','=',obj.cycle_id.id])
+ #schedule_obj=get_model("clinic.schedule")
+ #schedule_ids=schedule_obj.search(dom)
+ #schedule_obj.delete(schedule_ids)
+ #nurse_ids=[nurse['id'] for nurse in nurse_vals]
+ #for key, vals in schedules.items():
+ #vals['nurses']=[('add', nurse_ids)]
+ #schedule_obj.create(vals)
return {
'next': {
diff --git a/netforce_clinic/models/hd_case_discont.py b/netforce_clinic/models/hd_case_discont.py
index 1e05c27..6758d34 100644
--- a/netforce_clinic/models/hd_case_discont.py
+++ b/netforce_clinic/models/hd_case_discont.py
@@ -11,6 +11,7 @@ class HDCaseDiscont(Model):
def _get_hd_case_id(self,context={}):
hd_case_id=context.get("refer_id")
+ print("hd case deault")
if not hd_case_id:
return None
return int(hd_case_id)
diff --git a/netforce_clinic/models/load_nurse.py b/netforce_clinic/models/load_nurse.py
new file mode 100644
index 0000000..99062c9
--- /dev/null
+++ b/netforce_clinic/models/load_nurse.py
@@ -0,0 +1,80 @@
+from netforce.model import Model, fields, get_model
+
+class LoadNurse(Model):
+ _name="clinic.schedule.load.nurse"
+ _transient=True
+
+ _fields={
+ "schedule_id": fields.Many2One("clinic.schedule","Schedule",required=True,on_delete="cascade"),
+ 'categ_id': fields.Many2One("clinic.personal.categ","Category", domain=[['type','=','nurse']]),
+ "lines": fields.One2Many("clinic.schedule.load.nurse.line",'load_id', 'Lines'),
+ }
+
+ def _get_schedule_id(self,context={}):
+ schedule_id=context.get("refer_id")
+ if not schedule_id:
+ return None
+ return int(schedule_id)
+
+ def _get_lines(self,context={}):
+ cycle_ids=get_model("clinic.cycle").search([])
+ cycle_id=None
+ if cycle_ids:
+ cycle_id=cycle_ids[0]
+ lines=[]
+ print("cycle_id ", cycle_id)
+ for nurse in get_model("clinic.personal").search_browse([['type','=','nurse']]):
+ in_cycle_id=None
+ if nurse.cycle_id.id:
+ in_cycle_id=nurse.cycle_id.id
+ lines.append({
+ 'nurse_id': nurse.id,
+ 'cycle_id': in_cycle_id and in_cycle_id or cycle_id,
+ })
+ return lines
+
+
+ _defaults={
+ 'schedule_id': _get_schedule_id,
+ 'lines': _get_lines,
+ }
+
+ def copy2schedule(self,ids,context):
+ obj=self.browse(ids)[0]
+ schedule=get_model("clinic.schedule").browse(obj.schedule_id.id)
+ vals={
+ 'lines': [],
+ }
+
+ cycles=set()
+ for line in obj.lines:
+ nurse=line.nurse_id
+ cycle_id=line.cycle_id.id
+ cycles.update({cycle_id})
+ vals['lines'].append(('create',{
+ 'cycle_id': cycle_id,
+ 'nurse_id': nurse.id,
+ }))
+
+ for line in schedule.lines:
+ if line.cycle_id.id in list(cycles):
+ line.delete()
+
+ schedule.write(vals)
+ return {
+ 'next': {
+ 'name': 'clinic_schedule',
+ 'mode': 'form',
+ 'active_id': schedule.id,
+ },
+ 'flash': 'Copy nurse to schedule succesfully'
+ }
+
+ def onchange_categ(self,context={}):
+ data=context['data']
+ return data
+
+
+
+LoadNurse.register()
+
diff --git a/netforce_clinic/models/load_nurse_line.py b/netforce_clinic/models/load_nurse_line.py
new file mode 100644
index 0000000..26b6ca3
--- /dev/null
+++ b/netforce_clinic/models/load_nurse_line.py
@@ -0,0 +1,15 @@
+from netforce.model import Model, fields
+
+class LoadNurseLine(Model):
+ _name="clinic.schedule.load.nurse.line"
+ _transient=True
+
+ _fields={
+ "load_id": fields.Many2One("clinic.schedule.load.nurse","Load Nurse",required=True,on_delete="cascade"),
+ 'nurse_id': fields.Many2One("clinic.personal","Nurse",domain=[['type','=','nurse']]),
+ 'cycle_id': fields.Many2One("clinic.cycle", "Cycle"),
+ }
+
+
+LoadNurseLine.register()
+
diff --git a/netforce_clinic/models/personal.py b/netforce_clinic/models/personal.py
index e6e3217..cf9ac75 100644
--- a/netforce_clinic/models/personal.py
+++ b/netforce_clinic/models/personal.py
@@ -29,6 +29,16 @@ class Personal(Model):
res[obj.id]=level_id
return res
+ def _get_cycle(self,ids,context={}):
+ res={}
+ for obj in self.browse(ids):
+ cycle_id=None
+ for line in obj.cycles:
+ cycle=line.cycle_id
+ cycle_id=cycle.id
+ res[obj.id]=cycle_id
+ return res
+
_fields={
"number": fields.Char("Ref.",required=True,search=True),
"name": fields.Char("Name",required=True,search=True),
@@ -68,7 +78,9 @@ class Personal(Model):
'hire_date': fields.Date("Hire Date"),
'resign_date': fields.Date("Resign Date"),
"documents": fields.One2Many("document","related_id","Documents"),
- "moves": fields.One2Many("clinic.personal.move","personal_id","Moves"),
+ "moves": fields.One2Many("clinic.personal.move","personal_id","Personal Moves"),
+ "cycles": fields.One2Many("clinic.personal.cycle","personal_id","Working Cycles"),
+ 'cycle_id': fields.Many2One('clinic.cycle','Recent Cycle',function="_get_cycle"),
}
def _get_number(self,context={}):
diff --git a/netforce_clinic/models/personal_cycle.py b/netforce_clinic/models/personal_cycle.py
new file mode 100644
index 0000000..c2c0f56
--- /dev/null
+++ b/netforce_clinic/models/personal_cycle.py
@@ -0,0 +1,23 @@
+import time
+
+from netforce.model import Model, fields
+from netforce.access import get_active_company
+
+class PersonalCycle(Model):
+ _name="clinic.personal.cycle"
+ _string="Personal Cycle"
+
+ _fields={
+ "name": fields.Char("Description",search=True),
+ 'personal_id': fields.Many2One("clinic.personal","Personal",required=True),
+ 'cycle_id': fields.Many2One("clinic.cycle","Cycle",required=True),
+ 'date': fields.DateTime("Date"),
+ 'company_id': fields.Many2One("company","Company"),
+ }
+
+ _defaults={
+ "company_id": lambda *a: get_active_company(),
+ 'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
+ }
+
+PersonalCycle.register()
diff --git a/netforce_clinic/models/schedule.py b/netforce_clinic/models/schedule.py
index e27d09d..21f9c43 100644
--- a/netforce_clinic/models/schedule.py
+++ b/netforce_clinic/models/schedule.py
@@ -1,18 +1,17 @@
from datetime import datetime, timedelta
from netforce.model import Model, fields, get_model
-from netforce.access import get_active_company
+from netforce.access import get_active_company, get_active_user
class Schedule(Model):
_name="clinic.schedule"
_string="Schedule"
- #_field_name="cycle_id"
+ _field_name="date"
def _get_name(self,ids,context={}):
res={}
for obj in self.browse(ids):
- total_nurse=len(obj.nurses)
- res[obj.id]='%s, Nurse: %s'%(obj.cycle_id.name or "", total_nurse)
+ res[obj.id]='Schedule - %s'%(obj.date)
return res
def _get_item(self,ids,context={}):
@@ -26,23 +25,30 @@ class Schedule(Model):
return res
_fields={
- "name": fields.Char("Name",function="_get_name"),
- 'cycle_id': fields.Many2One("clinic.cycle","Cycle",required=True),
+ 'name': fields.Char("Name", function="_get_name"),
'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),
+ 'date': fields.Date("Date",required=True),
+ 'lines': fields.One2Many("clinic.schedule.line","schedule_id","Lines"),
'company_id': fields.Many2One("company","Company"),
- 'nurses': fields.Many2Many('clinic.personal','Nurses'), # XXX domain
'state': fields.Selection([['draft','Draft'],['confirmed', 'Confirmed']],'State'),
+ 'user_id': fields.Many2One("base.user","User"),
}
_defaults={
+ 'user_id': lambda *a: get_active_user(),
"company_id": lambda *a: get_active_company(),
+ 'date': lambda *a: datetime.now().strftime("%Y-%m-%d"),
'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',
}
+ _sql_constraints=[
+ ('schedule_uniq','unique (date,company_id)','Date should be unique'),
+ ]
+
def confirm(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({
@@ -58,27 +64,32 @@ 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)],
+ 'lines': [],
}
- obj_id=get_model("clinic.schedule").create(vals)
+ 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)
return {
'next': {
'name': 'clinic_schedule',
'mode': 'form',
- 'active_id': obj_id,
+ 'active_id': new_id,
},
- 'flash': 'Copy schedule successfully',
+ 'flash': 'Copy schedule from %s to %s successfully'%(obj.date,new_obj.date)
}
- def copy_nurses(self,ids,context={}):
+ def copy2cycle_item(self,ids,context={}):
obj=self.browse(ids)[0]
nurses=[]
- for nurse in obj.nurses:
+ for line in obj.lines:
+ nurse=line.nurse_id
nurses.append(('create',{
'nurse_id': nurse.id,
'level_id': nurse.level_id.id,
@@ -99,32 +110,40 @@ class Schedule(Model):
'flash': 'Copy nurses to cycle item successfully',
}
- def view_cycle_item(self,ids,context={}):
- obj=self.browse(ids)[0]
- item_id=obj.cycle_item_id.id
- msg=''
- if not item_id:
- # XXX
- item_id=get_model("clinic.cycle.item").create({
- 'cycle_id': obj.cycle_id.id,
- 'date': obj.time_start[0:10],
+ 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,
})
- #raise Exception("No found cycle item")
- item_nurse_obj=get_model("clinic.cycle.item.nurse")
- for nurse in obj.nurses:
- item_nurse_obj.create({
- 'cycle_item_id': item_id,
- 'nurse_id': nurse.id,
- 'level_id': nurse.level_id.id,
- })
- msg='Create Cycle Item successfully'
+ 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()
return {
'next': {
- 'name': 'clinic_cycle_item',
+ 'name': 'clinic_schedule',
'mode': 'form',
- 'active_id': item_id,
+ 'active_id': obj.id,
},
- 'flash': msg,
+ 'flash': 'List of nurse has been cleared.',
}
Schedule.register()
+
diff --git a/netforce_clinic/models/schedule.py.old b/netforce_clinic/models/schedule.py.old
new file mode 100644
index 0000000..77ef06f
--- /dev/null
+++ b/netforce_clinic/models/schedule.py.old
@@ -0,0 +1,130 @@
+from datetime import datetime, timedelta
+
+from netforce.model import Model, fields, get_model
+from netforce.access import get_active_company
+
+class Schedule(Model):
+ _name="clinic.schedule"
+ _string="Schedule"
+ #_field_name="cycle_id"
+
+ def _get_name(self,ids,context={}):
+ res={}
+ for obj in self.browse(ids):
+ nurse_list=','.join(nurse.name for nurse in obj.nurses)
+ res[obj.id]='%s, Nurse: %s'%(obj.cycle_id.name or "", nurse_list)
+ 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"),
+ 'nurses': fields.Many2Many('clinic.personal','Nurses'), # XXX domain
+ 'state': fields.Selection([['draft','Draft'],['confirmed', 'Confirmed']],'State'),
+ }
+
+ _defaults={
+ "company_id": lambda *a: get_active_company(),
+ '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',
+ }
+
+ 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',
+ })
+
+
+ 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=obj.cycle_item_id.id
+ msg=''
+ if not item_id:
+ # XXX
+ item_id=get_model("clinic.cycle.item").create({
+ 'cycle_id': obj.cycle_id.id,
+ 'date': obj.time_start[0:10],
+ })
+ #raise Exception("No found cycle item")
+ item_nurse_obj=get_model("clinic.cycle.item.nurse")
+ for nurse in obj.nurses:
+ item_nurse_obj.create({
+ 'cycle_item_id': item_id,
+ 'nurse_id': nurse.id,
+ 'level_id': nurse.level_id.id,
+ })
+ msg='Create Cycle Item successfully'
+ return {
+ 'next': {
+ 'name': 'clinic_cycle_item',
+ 'mode': 'form',
+ 'active_id': item_id,
+ },
+ 'flash': msg,
+ }
+
+Schedule.register()
diff --git a/netforce_clinic/models/schedule_line.py b/netforce_clinic/models/schedule_line.py
new file mode 100644
index 0000000..e5393ad
--- /dev/null
+++ b/netforce_clinic/models/schedule_line.py
@@ -0,0 +1,13 @@
+from netforce.model import Model, fields
+
+class ScheduleLine(Model):
+ _name="clinic.schedule.line"
+ _string="Schedule Line"
+
+ _fields={
+ 'schedule_id': fields.Many2One("clinic.schedule","Schedule"),
+ 'cycle_id': fields.Many2One("clinic.cycle","Cycle"),
+ "nurse_id": fields.Many2One("clinic.personal","Nurse",domain=[['type','=','nurse']]),
+ }
+
+ScheduleLine.register()
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt
index fa35e2f..7c08c6d 100644
--- a/netforce_clinic/todo.txt
+++ b/netforce_clinic/todo.txt
@@ -4,5 +4,7 @@ cycle dialy
-list
visit dialy
list of visits
+schedule planing for nurses / personal
+
import payment
- error report