prevent duplicate staff
parent
173c8e599e
commit
1c16736a0f
|
@ -74,15 +74,31 @@
|
||||||
<field name="hd_case_id"/>
|
<field name="hd_case_id"/>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
<field name="cycle_item_nurses" readonly="1" attrs='{"invisible":[["type","=","doctor"]]}'>
|
<field name="cycle_item_lines" readonly="1" attrs='{"invisible":[["type","=","doctor"]]}'>
|
||||||
<list>
|
<list colors='{"#9f9":[["cstate","=","validated"]]}'>
|
||||||
<field name="cycle_item_id"/>
|
<field name="cycle_item_id"/>
|
||||||
|
<field name="pt_total"/>
|
||||||
|
<field name="cstate"/>
|
||||||
</list>
|
</list>
|
||||||
<form>
|
<form>
|
||||||
<field name="cycle_item_id"/>
|
<field name="cycle_item_id" readonly="1"/>
|
||||||
|
<field name="cstate"/>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
<field name="patients" readonly="1"/>
|
<!--<field name="patients">-->
|
||||||
|
<field name="patients" attrs='{"readonly":1,"invisible":[["type","in",["nurse","staff"]]]}'>
|
||||||
|
<list>
|
||||||
|
<field name="reg_date"/>
|
||||||
|
<field name="hn_no"/>
|
||||||
|
<field name="trt_no"/>
|
||||||
|
<field name="card_no"/>
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="type_id"/>
|
||||||
|
<field name="department_id"/>
|
||||||
|
<field name="walkin"/>
|
||||||
|
<field name="dispose"/>
|
||||||
|
</list>
|
||||||
|
</field>
|
||||||
<field name="comments"/>
|
<field name="comments"/>
|
||||||
</related>
|
</related>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -4,12 +4,25 @@ class CycleItemLine(Model):
|
||||||
_name="clinic.cycle.item.line"
|
_name="clinic.cycle.item.line"
|
||||||
_string="Cycle Item Nurse"
|
_string="Cycle Item Nurse"
|
||||||
|
|
||||||
|
def _get_all(self,ids,context={}):
|
||||||
|
res={}
|
||||||
|
for obj in self.browse(ids):
|
||||||
|
citem=obj.cycle_item_id
|
||||||
|
pt_total=len([hdcase for hdcase in citem.hd_cases if hdcase.state in ('waiting_payment','paid')])
|
||||||
|
res[obj.id]={
|
||||||
|
'cstate': citem.state,
|
||||||
|
'pt_total': pt_total,
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
|
||||||
_fields={
|
_fields={
|
||||||
'cycle_item_id': fields.Many2One("clinic.cycle.item", "Cycle Item"),
|
'cycle_item_id': fields.Many2One("clinic.cycle.item", "Cycle Item"),
|
||||||
'level_id': fields.Many2One("clinic.staff.level", "Level",),
|
'level_id': fields.Many2One("clinic.staff.level", "Level",),
|
||||||
'nurse_id': fields.Many2One("clinic.staff",'Nurse',domain=[['type','=','nurse']]),
|
'nurse_id': fields.Many2One("clinic.staff",'Nurse',domain=[['type','=','nurse']]),
|
||||||
'department_id': fields.Many2One("clinic.department","Department"),
|
'department_id': fields.Many2One("clinic.department","Department"),
|
||||||
"state": fields.Selection([["part_time","Part Time"],["full_time","Full Time"]],"Working Status",search=True),
|
"state": fields.Selection([["part_time","Part Time"],["full_time","Full Time"]],"Working Status",search=True),
|
||||||
|
"cstate": fields.Selection([("draft","Draft"),('pending','Pending'),("validated","Validated")],"Status",function="_get_all",function_multi=True),
|
||||||
|
"pt_total": fields.Integer("Patients",function="_get_all",function_multi=True),
|
||||||
'categ_id': fields.Many2One("clinic.staff.categ",'Category',domain=[['type','=','nurse']]),
|
'categ_id': fields.Many2One("clinic.staff.categ",'Category',domain=[['type','=','nurse']]),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@ class ReportLaborCostSummary(Model):
|
||||||
branch_id=defaults.get("branch_id")
|
branch_id=defaults.get("branch_id")
|
||||||
categ_id=defaults.get("categ_id")
|
categ_id=defaults.get("categ_id")
|
||||||
cycle_id=defaults.get("cycle_id")
|
cycle_id=defaults.get("cycle_id")
|
||||||
|
if cycle_id:
|
||||||
|
cycle_id=int(cycle_id)
|
||||||
if categ_id:
|
if categ_id:
|
||||||
categ_id=int(categ_id)
|
categ_id=int(categ_id)
|
||||||
if branch_id:
|
if branch_id:
|
||||||
|
@ -63,9 +65,9 @@ class ReportLaborCostSummary(Model):
|
||||||
'department_id': department_id or None,
|
'department_id': department_id or None,
|
||||||
'branch_id': branch_id or None,
|
'branch_id': branch_id or None,
|
||||||
'only_value': True,
|
'only_value': True,
|
||||||
'categ_id': categ_id,
|
'categ_id': categ_id or None,
|
||||||
'level_id': level_id,
|
'level_id': level_id or None,
|
||||||
'cycle_id': cycle_id,
|
'cycle_id': cycle_id or None,
|
||||||
}
|
}
|
||||||
print('res ', res)
|
print('res ', res)
|
||||||
return res
|
return res
|
||||||
|
@ -113,8 +115,9 @@ class ReportLaborCostSummary(Model):
|
||||||
dom.append(['labor_cost_id.cycle_item_id.cycle_id','=',cycle_id])
|
dom.append(['labor_cost_id.cycle_item_id.cycle_id','=',cycle_id])
|
||||||
staffs={}
|
staffs={}
|
||||||
citems={}
|
citems={}
|
||||||
print('>> dom: ', dom)
|
print('--> dom: ', dom)
|
||||||
total_hdcase=0
|
total_hdcase=0
|
||||||
|
|
||||||
for line in get_model("clinic.labor.cost.line").search_browse(dom):
|
for line in get_model("clinic.labor.cost.line").search_browse(dom):
|
||||||
lcost=line.labor_cost_id
|
lcost=line.labor_cost_id
|
||||||
citem=lcost.cycle_item_id
|
citem=lcost.cycle_item_id
|
||||||
|
|
|
@ -161,16 +161,107 @@ class ClinicSetting(Model):
|
||||||
if user_id !=1:
|
if user_id !=1:
|
||||||
print("Only admin!!")
|
print("Only admin!!")
|
||||||
return
|
return
|
||||||
#path='/tmp/test'
|
pts={}
|
||||||
#self.update_pcycle(path,['ls1.csv','ls2.csv','ls3.csv'])
|
for pt in get_model("clinic.patient").search_browse([]):
|
||||||
|
name='%s %s'%(pt.first_name or "", pt.last_name or "")
|
||||||
|
if not pts.get(name):
|
||||||
|
pts[name]=[]
|
||||||
|
pts[name].append({
|
||||||
|
'id': pt.id,
|
||||||
|
'name': name,
|
||||||
|
'date': pt.reg_date,
|
||||||
|
'branch_id': pt.department_id.id,
|
||||||
|
})
|
||||||
|
sts={}
|
||||||
|
for st in get_model("clinic.staff").search_browse([]):
|
||||||
|
name='%s %s'%(st.first_name or '', st.last_name or '')
|
||||||
|
if not sts.get(name):
|
||||||
|
sts[name]=[]
|
||||||
|
sts[name].append({
|
||||||
|
'id': st.id,
|
||||||
|
'name': name,
|
||||||
|
'branch_id': st.department_id.id,
|
||||||
|
'type': st.type,
|
||||||
|
'date': st.date,
|
||||||
|
})
|
||||||
|
|
||||||
|
print('='*50, 'staffs duplicate')
|
||||||
|
for st, vals in sts.items():
|
||||||
|
vals=sorted(vals,key=lambda x: x['date'])
|
||||||
|
count=len(vals)
|
||||||
|
if count > 1:
|
||||||
|
print("z"*50)
|
||||||
|
id_lines=[]
|
||||||
|
no=0
|
||||||
|
for val in vals:
|
||||||
|
no+=1
|
||||||
|
staff_id=val['id']
|
||||||
|
staff_type=val['type']
|
||||||
|
if staff_type=='nurse':
|
||||||
|
res=get_model("clinic.cycle.item.line").search_browse([['nurse_id','=',staff_id]])
|
||||||
|
if len(res)<=0:
|
||||||
|
print('nurse zero delete ', st)
|
||||||
|
get_model('clinic.staff').delete([staff_id])
|
||||||
|
else:
|
||||||
|
print('merge nurse... ', st, staff_id, val['date'], val['branch_id'], len(res))
|
||||||
|
print('no ', no, len(vals), len(res))
|
||||||
|
if no==len(vals):
|
||||||
|
print("--> ", staff_id, id_lines)
|
||||||
|
for id_line in id_lines:
|
||||||
|
for rec in get_model("clinic.cycle.item.line").search_browse([['nurse_id','=',id_line]]):
|
||||||
|
rec.write({
|
||||||
|
'nurse_id': staff_id,
|
||||||
|
})
|
||||||
|
dom=[
|
||||||
|
['type','=','nurse'],
|
||||||
|
['staff_id','=',id_line],
|
||||||
|
]
|
||||||
|
for lcost in get_model("clinic.labor.cost.line").search_browse(dom):
|
||||||
|
lcost.write({
|
||||||
|
'staff_id': staff_id,
|
||||||
|
})
|
||||||
|
id_lines.append(staff_id)
|
||||||
|
elif staff_type=='doctor':
|
||||||
|
res=get_model("clinic.hd.case.staff").search_browse([['staff_id','=',staff_id]])
|
||||||
|
if len(res)<=0:
|
||||||
|
print('doctor zero delete ', st)
|
||||||
|
get_model('clinic.staff').delete([staff_id])
|
||||||
|
else:
|
||||||
|
print('merge doctor... ', st, staff_id, val['date'], val['branch_id'], len(res))
|
||||||
|
if no==len(vals):
|
||||||
|
print("--> ", staff_id, id_lines)
|
||||||
|
db=get_connection()
|
||||||
|
for id_line in id_lines:
|
||||||
|
for rec in get_model("clinic.hd.case.staff").search_browse([['staff_id','=',id_line]]):
|
||||||
|
rec.write({
|
||||||
|
'staff_id': staff_id,
|
||||||
|
})
|
||||||
|
hdcase=rec.hd_case_id
|
||||||
|
vs=hdcase.visit_id
|
||||||
|
#vs.write({
|
||||||
|
#'doctor_id': staff_id,
|
||||||
|
#})
|
||||||
|
db.execute("update clinic_visit set doctor_id=%s where id=%s",staff_id,vs.id)
|
||||||
|
pt=hdcase.patient_id
|
||||||
|
#pt.write({
|
||||||
|
#'doctor_id': staff_id,
|
||||||
|
#})
|
||||||
|
db.execute("update clinic_patient set doctor_id=%s where id=%s",staff_id,pt.id)
|
||||||
|
citem=hdcase.cycle_item_id
|
||||||
|
dom=[
|
||||||
|
['type','=','doctor'],
|
||||||
|
['staff_id','=',id_line],
|
||||||
|
['labor_cost_id.cycle_item_id','=',citem.id],
|
||||||
|
]
|
||||||
|
for lcost in get_model("clinic.labor.cost.line").search_browse(dom):
|
||||||
|
lcost.write({
|
||||||
|
'staff_id': staff_id,
|
||||||
|
})
|
||||||
|
id_lines.append(staff_id)
|
||||||
|
print("z"*50)
|
||||||
###TODO remove douplicate patient
|
###TODO remove douplicate patient
|
||||||
###TODO remove douplicate staff
|
###TODO remove douplicate staff
|
||||||
###TODO remove douplicate visit
|
###TODO remove douplicate visit
|
||||||
obj=self.browse(ids)[0]
|
|
||||||
for ap_line in obj.account_patients:
|
|
||||||
pt=ap_line.patient_id
|
|
||||||
if not pt:
|
|
||||||
ap_line.delete()
|
|
||||||
print("Done!")
|
print("Done!")
|
||||||
|
|
||||||
def multi_department(self,ids,context={}):
|
def multi_department(self,ids,context={}):
|
||||||
|
|
|
@ -108,6 +108,22 @@ class Staff(Model):
|
||||||
res[obj.id]=','.join([dpt.name for dpt in obj.departments])
|
res[obj.id]=','.join([dpt.name for dpt in obj.departments])
|
||||||
set_active_user(user_id)
|
set_active_user(user_id)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def _get_all(self,ids,context={}):
|
||||||
|
res={}
|
||||||
|
for obj in self.browse(ids):
|
||||||
|
pt_ids=[]
|
||||||
|
if obj.type=='doctor':
|
||||||
|
pt_ids=get_model("clinic.patient").search([['doctor_id','=',obj.id]])
|
||||||
|
elif obj.type=='nurse':
|
||||||
|
p=set()
|
||||||
|
for cline in obj.cycle_item_lines:
|
||||||
|
citem=cline.cycle_item_id
|
||||||
|
for hdcase in citem.hd_cases:
|
||||||
|
p.update({hdcase.patient_id.id})
|
||||||
|
pt_ids=list(p)
|
||||||
|
res[obj.id]=pt_ids
|
||||||
|
return res
|
||||||
|
|
||||||
_fields={
|
_fields={
|
||||||
'employee_id': fields.Many2One("hr.employee","Employee"),
|
'employee_id': fields.Many2One("hr.employee","Employee"),
|
||||||
|
@ -135,7 +151,8 @@ class Staff(Model):
|
||||||
"prof_license_expiry" : fields.Date("Expired License"),
|
"prof_license_expiry" : fields.Date("Expired License"),
|
||||||
"birthday": fields.Date("BirthDay",search=True),
|
"birthday": fields.Date("BirthDay",search=True),
|
||||||
"department_id": fields.Many2One("clinic.department", "Department",search=True),
|
"department_id": fields.Many2One("clinic.department", "Department",search=True),
|
||||||
"patients": fields.One2Many("clinic.patient","doctor_id","Patients"),
|
#"patients": fields.One2Many("clinic.patient","doctor_id","Patients"),
|
||||||
|
"patients": fields.Many2Many("clinic.patient","Patients",function="_get_all"),
|
||||||
"addresses": fields.One2Many("address","staff_id","Addresses"),
|
"addresses": fields.One2Many("address","staff_id","Addresses"),
|
||||||
"comments": fields.One2Many("message","related_id","Comments"),
|
"comments": fields.One2Many("message","related_id","Comments"),
|
||||||
"nurse_visits": fields.One2Many("clinic.visit","nurse_id","Visits"),
|
"nurse_visits": fields.One2Many("clinic.visit","nurse_id","Visits"),
|
||||||
|
@ -160,7 +177,7 @@ class Staff(Model):
|
||||||
'cycle_id': fields.Many2One('clinic.cycle','Last Cycle',function="_get_cycle"),
|
'cycle_id': fields.Many2One('clinic.cycle','Last Cycle',function="_get_cycle"),
|
||||||
"hd_case_staffs": fields.One2Many("clinic.hd.case.staff","staff_id","HD Cases"),
|
"hd_case_staffs": fields.One2Many("clinic.hd.case.staff","staff_id","HD Cases"),
|
||||||
"hd_cases": fields.Many2Many("clinic.hd.case","HD Cases",function="_get_hdcase"), # not need to use (it's slow to load)
|
"hd_cases": fields.Many2Many("clinic.hd.case","HD Cases",function="_get_hdcase"), # not need to use (it's slow to load)
|
||||||
"cycle_item_nurses": fields.One2Many("clinic.cycle.item.line","nurse_id","Cycle Items"),
|
"cycle_item_lines": fields.One2Many("clinic.cycle.item.line","nurse_id","Cycle Items"),
|
||||||
'branch_id': fields.Many2One("clinic.branch","Branch", search=True),
|
'branch_id': fields.Many2One("clinic.branch","Branch", search=True),
|
||||||
"partner_id": fields.Many2One("partner","Contact"),
|
"partner_id": fields.Many2One("partner","Contact"),
|
||||||
'departments': fields.Many2Many("clinic.department","Departments"),
|
'departments': fields.Many2Many("clinic.department","Departments"),
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
> script:
|
> script:
|
||||||
merge staff, patient
|
merge staff, patient
|
||||||
|
source => destination
|
||||||
|
- step:
|
||||||
|
> patient:
|
||||||
|
1. copy:
|
||||||
|
- properties
|
||||||
|
- visit
|
||||||
|
- hdcases
|
||||||
|
- dialyzers
|
||||||
|
2. delete old one
|
||||||
|
> staff:
|
||||||
|
|
||||||
> invoice payment on rd shop
|
> invoice payment on rd shop
|
||||||
|
|
||||||
> report:
|
|
||||||
improve cycle item report
|
|
||||||
|
|
Loading…
Reference in New Issue