diff --git a/netforce_clinic/layouts/clinic_cycle_item_form.xml b/netforce_clinic/layouts/clinic_cycle_item_form.xml index df84332..7ca9898 100644 --- a/netforce_clinic/layouts/clinic_cycle_item_form.xml +++ b/netforce_clinic/layouts/clinic_cycle_item_form.xml @@ -3,6 +3,7 @@ @@ -18,7 +19,7 @@ - + diff --git a/netforce_clinic/layouts/clinic_department_form.xml b/netforce_clinic/layouts/clinic_department_form.xml index 087ddfe..817dd10 100644 --- a/netforce_clinic/layouts/clinic_department_form.xml +++ b/netforce_clinic/layouts/clinic_department_form.xml @@ -6,6 +6,7 @@ + diff --git a/netforce_clinic/layouts/clinic_patient_list.xml b/netforce_clinic/layouts/clinic_patient_list.xml index 5cad13f..3ca061d 100644 --- a/netforce_clinic/layouts/clinic_patient_list.xml +++ b/netforce_clinic/layouts/clinic_patient_list.xml @@ -6,9 +6,9 @@ + - diff --git a/netforce_clinic/layouts/clinic_staff_list.xml b/netforce_clinic/layouts/clinic_staff_list.xml index a8a8f97..9d7ee65 100644 --- a/netforce_clinic/layouts/clinic_staff_list.xml +++ b/netforce_clinic/layouts/clinic_staff_list.xml @@ -9,11 +9,11 @@ + - diff --git a/netforce_clinic/models/cycle_item.py b/netforce_clinic/models/cycle_item.py index 7314afe..1b910f5 100644 --- a/netforce_clinic/models/cycle_item.py +++ b/netforce_clinic/models/cycle_item.py @@ -17,7 +17,8 @@ class CycleItem(Model): cycle_name='' if cycle: cycle_name=cycle.name - name="%s-%s"%(cycle_name,obj.date) + dpt=obj.department_id + name="%s-%s-%s"%(cycle_name,obj.date,dpt.name) res[obj.id]={ 'name': name, 'sequence':'%s-%s-%s-%s'%(obj.date,cycle.sequence,obj.branch_id.id,obj.department_id.id), @@ -168,21 +169,23 @@ class CycleItem(Model): obj=self.browse(ids)[0] #TODO check cycle number & date from schedule schedules=get_model("clinic.schedule").search_browse([['date','=',obj.date]]) - nurses=[] + lines=[] for schedule in schedules: for line in schedule.lines: cycle=line.cycle_id if obj.cycle_id.id==cycle.id: nurse=line.nurse_id level=line.level_id - nurses.append(('create',{ + lines.append(('create',{ 'nurse_id': nurse.id, 'level_id': level.id, })) - for nurse in obj.nurses: - nurse.delete() + for line in obj.lines: + line.delete() + if not lines: + raise Exception("Nurse not found in schedule %s"%obj.date) obj.write({ - 'nurses': nurses, + 'lines': lines, }) return { @@ -193,5 +196,36 @@ class CycleItem(Model): }, 'flash': 'Load nurse from schedule to cycle item successfully', } + + def update_hdcase(self,ids,context={}): + obj=self.browse(ids)[0] + dpt=obj.department_id + branch=obj.branch_id + cycle=obj.cycle_id + company=obj.company_id + date=obj.date + dom=[ + ['cycle_id','=',cycle.id], + ['date','=',date], + ['company_id','=',company.id], + ['branch_id','=',branch.id], + ['department_id','=',dpt.id], + ] + for hdcase in get_model("clinic.hd.case").search_browse(dom): + hdcase.write({ + 'cycle_item_id': obj.id, + }) + vs=hdcase.visit_id + vs.write({ + 'cycle_item_id': obj.id, + }) + return { + 'next': { + 'name': 'clinic_cycle_item', + 'mode': 'form', + 'active_id': obj.id, + }, + 'flash': 'Update HDCase successfully', + } CycleItem.register() diff --git a/netforce_clinic/models/cycle_item_line.py b/netforce_clinic/models/cycle_item_line.py index edafd6c..1d9bf8f 100644 --- a/netforce_clinic/models/cycle_item_line.py +++ b/netforce_clinic/models/cycle_item_line.py @@ -8,6 +8,7 @@ class CycleItemLine(Model): 'cycle_item_id': fields.Many2One("clinic.cycle.item", "Cycle Item"), '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"), } CycleItemLine.register() diff --git a/netforce_clinic/models/department.py b/netforce_clinic/models/department.py index b2596fe..87ed72a 100644 --- a/netforce_clinic/models/department.py +++ b/netforce_clinic/models/department.py @@ -14,6 +14,7 @@ class Department(Model): 'branch_id': fields.Many2One("clinic.branch","Branch"), "pick_out_journal_id": fields.Many2One("stock.journal","Stock Journal",required=True), 'patients': fields.One2Many("clinic.patient","department_id","Patients"), + 'staffs': fields.One2Many("clinic.staff","department_id","Staffs"), } def _get_branch(self,context={}): @@ -26,4 +27,6 @@ class Department(Model): 'branch_id': _get_branch, } + _order="name" + Department.register() diff --git a/netforce_clinic/models/labor_cost.py b/netforce_clinic/models/labor_cost.py index 5097bba..cbb264d 100644 --- a/netforce_clinic/models/labor_cost.py +++ b/netforce_clinic/models/labor_cost.py @@ -96,10 +96,11 @@ class LaborCost(Model): levels.update(vals) item=obj.cycle_item_id - for ns in item.nurses: - level=ns.level_id + for line in item.lines: + level=line.level_id + nurse=line.nurse_id if not level: - raise Exception("Please specify level for %s"%ns.nurse_id.name) + raise Exception("Please specify level for %s"%nurse.name) levels[level.id]['total']+=1 st_levels={} @@ -236,9 +237,9 @@ class LaborCost(Model): item=obj.cycle_item_id lines=[] # cost's nurses - for nr in item.nurses: - nurse=nr.nurse_id - level=nr.level_id + for line in item.lines: + nurse=line.nurse_id + level=line.level_id vals=levels.get(level.id) rate,amt,qty=0.0,0.0,0 level_id=level.id diff --git a/netforce_clinic/models/labor_cost_formular.py b/netforce_clinic/models/labor_cost_formular.py index 16b9202..9d33777 100644 --- a/netforce_clinic/models/labor_cost_formular.py +++ b/netforce_clinic/models/labor_cost_formular.py @@ -7,7 +7,7 @@ class LaborCostFormular(Model): _name_field="labor_cost_id" _fields={ - "labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True), + "labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True,on_delete="cascade"), 'level_id': fields.Many2One("clinic.staff.level", "Level",domain=[['type','=','nurse']]), 'qty': fields.Integer("Qty"), 'var_a': fields.Float("A"), diff --git a/netforce_clinic/models/labor_cost_line.py b/netforce_clinic/models/labor_cost_line.py index 29e6b52..636bfbb 100644 --- a/netforce_clinic/models/labor_cost_line.py +++ b/netforce_clinic/models/labor_cost_line.py @@ -7,7 +7,7 @@ class LaborCostLine(Model): _name_field="labor_cost_id" _fields={ - "labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True), + "labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True,on_delete="cascade"), "type": fields.Selection([('staff','Staff'),("doctor","Doctor"),('nurse','Nurse')],"Type",required=True,search=True), 'staff_id': fields.Many2One("clinic.staff", "Staff",search=True), 'level_id': fields.Many2One("clinic.staff.level", "Level",search=True), diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py index 1521711..7b7ec93 100644 --- a/netforce_clinic/models/setting.py +++ b/netforce_clinic/models/setting.py @@ -92,30 +92,42 @@ class ClinicSetting(Model): def run_script(self,ids,context={}): 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, - #}) - # create new cycle item - # TODO - # copy old schedule - # copy old nurse to schedule - # delete old cycle item - # confirm schedule - # set visit & hd case to cycle item - old_schd=[] - for schd in get_model("clinic.schedule").search_browse([]): - if schd.lines: - print("x") - pass - for citem in get_model("clinic.cycle.item").search_browse([]): - if citem.lines: - print("y") + 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, + }) + #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() + #return + ############################################# print("Done!") def reset_last_import(self,ids,context={}): diff --git a/netforce_clinic/models/sickbed.py b/netforce_clinic/models/sickbed.py index 57ff2d3..3884c90 100644 --- a/netforce_clinic/models/sickbed.py +++ b/netforce_clinic/models/sickbed.py @@ -58,7 +58,7 @@ class SickBed(Model): 'branch_id': _get_branch, } - _order="sequence" + _order="sequence,name" def copy(self,ids,context={}): obj=self.browse(ids)[0] diff --git a/netforce_clinic/models/staff.py b/netforce_clinic/models/staff.py index d43fa4b..394f9c5 100644 --- a/netforce_clinic/models/staff.py +++ b/netforce_clinic/models/staff.py @@ -97,7 +97,7 @@ class Staff(Model): "nurse_visits": fields.One2Many("clinic.visit","nurse_id","Visits"), "doctor_visits": fields.One2Many("clinic.visit","doctor_id","Visits"), "company_id": fields.Many2One("company","Company",search=True), - "user_id": fields.Many2One("base.user","User"), + "user_id": fields.Many2One("base.user","User",search=True), 'image': fields.File("Image"), 'note': fields.Text("Note"), 'categ_id': fields.Many2One("clinic.staff.categ", "Category"), diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt index c7b6bf0..a105c72 100644 --- a/netforce_clinic/todo.txt +++ b/netforce_clinic/todo.txt @@ -1,7 +1,7 @@ todo: - XXXX - make a script to generate cycle item - - accounting + - make a sharing setting - filter data 1. company