diff --git a/netforce_clinic/layouts/clinic_cycle_item_form.xml b/netforce_clinic/layouts/clinic_cycle_item_form.xml
index 394962d..4b3f75f 100644
--- a/netforce_clinic/layouts/clinic_cycle_item_form.xml
+++ b/netforce_clinic/layouts/clinic_cycle_item_form.xml
@@ -28,6 +28,15 @@
+
+
+
+
+
+
+
Note: HD Case State Accepted:
'Finish Treatment', 'Waiting Payment', 'Paid'.
+
+
diff --git a/netforce_clinic/layouts/clinic_labor_cost_form.xml b/netforce_clinic/layouts/clinic_labor_cost_form.xml
index 125fb5d..ecc44b3 100644
--- a/netforce_clinic/layouts/clinic_labor_cost_form.xml
+++ b/netforce_clinic/layouts/clinic_labor_cost_form.xml
@@ -30,7 +30,8 @@
-
+
+
@@ -41,9 +42,12 @@
-
+
+
+
+
@@ -60,6 +64,7 @@
+
diff --git a/netforce_clinic/layouts/clinic_patient_form.xml b/netforce_clinic/layouts/clinic_patient_form.xml
index 3ba1d5d..9a729fc 100644
--- a/netforce_clinic/layouts/clinic_patient_form.xml
+++ b/netforce_clinic/layouts/clinic_patient_form.xml
@@ -19,6 +19,7 @@
+
@@ -65,13 +66,14 @@
+
-
+
diff --git a/netforce_clinic/layouts/clinic_report_hd_case_summary.xml b/netforce_clinic/layouts/clinic_report_hd_case_summary.xml
index 70faa49..5a4be2a 100644
--- a/netforce_clinic/layouts/clinic_report_hd_case_summary.xml
+++ b/netforce_clinic/layouts/clinic_report_hd_case_summary.xml
@@ -1,5 +1,7 @@
diff --git a/netforce_clinic/layouts/clinic_report_labor_cost_summary.xml b/netforce_clinic/layouts/clinic_report_labor_cost_summary.xml
index 64c89e2..6b11d67 100644
--- a/netforce_clinic/layouts/clinic_report_labor_cost_summary.xml
+++ b/netforce_clinic/layouts/clinic_report_labor_cost_summary.xml
@@ -4,6 +4,8 @@
+
+
diff --git a/netforce_clinic/layouts/clinic_setting.xml b/netforce_clinic/layouts/clinic_setting.xml
index 1586bc7..ebbbc78 100644
--- a/netforce_clinic/layouts/clinic_setting.xml
+++ b/netforce_clinic/layouts/clinic_setting.xml
@@ -30,7 +30,7 @@
-
+
diff --git a/netforce_clinic/models/cycle_item.py b/netforce_clinic/models/cycle_item.py
index d251b08..8d1d8f0 100644
--- a/netforce_clinic/models/cycle_item.py
+++ b/netforce_clinic/models/cycle_item.py
@@ -97,6 +97,9 @@ class CycleItem(Model):
def validate(self,ids,context={}):
obj=self.browse(ids)[0]
+ for hdcase in obj.hd_cases:
+ if hdcase.state not in ('completed','waiting_payment','paid'):
+ raise Exception('Invalidate cycle item %s: HD Case %s is not completed' % (obj.name, hdcase.patient_id.name))
for obj_id in ids:
lcost_ids=get_model("clinic.labor.cost").search([['cycle_item_id','=',obj_id]])
labor_cost=get_model("clinic.labor.cost")
@@ -128,6 +131,12 @@ class CycleItem(Model):
def to_draft(self,ids,context={}):
for obj in self.browse(ids):
+ dom=[
+ ['cycle_item_id','=',obj.id]
+ ]
+ for lcost in get_model("clinic.labor.cost").search_browse(dom):
+ print("labor cost of cycle item % s is deleted"%lcost.cycle_item_id.name)
+ lcost.delete()
obj.write({
'state': 'draft',
})
diff --git a/netforce_clinic/models/labor_cost.py b/netforce_clinic/models/labor_cost.py
index 2ccb51d..be8fbcd 100644
--- a/netforce_clinic/models/labor_cost.py
+++ b/netforce_clinic/models/labor_cost.py
@@ -39,13 +39,22 @@ class LaborCost(Model):
if total_a:
var_x=eval('(%s%s)/%s'%(var_ptx,total_bstr,total_a))
+ total_nqty=0
+ total_formular=0
+ for line in obj.formulars:
+ total_nqty+=line.qty or 0
+ total_formular+=line.amount or 0
+
total_ncost=0.0
for line in obj.nurse_lines:
- total_ncost+=line.amount or 0.0
+ #total_ncost+=line.amount or 0.0
+ total_ncost+=line.rate or 0.0
total_dcost=0.0
+ total_dqty=0.0
for line in obj.doctor_lines:
total_dcost+=line.amount or 0.0
+ total_dqty+=line.qty or 0.0
total_stcost=0.0
for line in obj.staff_lines:
@@ -60,8 +69,11 @@ class LaborCost(Model):
'var_fml3': '(%s%s)/%s'%(var_ptx,total_bstr,total_a),
'var_x': round(var_x,2),
'total': total,
+ 'total_formular': total_formular,
'total_ncost': total_ncost,
+ 'total_nqty': total_nqty,
'total_dcost': total_dcost,
+ 'total_dqty': total_dqty,
'total_stcost': total_stcost,
}
@@ -77,8 +89,11 @@ class LaborCost(Model):
'var_fml3': fields.Char("X:",function="_get_all",function_multi=True),
'var_x': fields.Char("X:",function="_get_all",function_multi=True),
'total': fields.Float("Total (Baht)",function="_get_all",function_multi=True),
+ 'total_formular': fields.Float("Total",function="_get_all",function_multi=True),
'total_ncost': fields.Float("Nurse Cost",function="_get_all",function_multi=True),
+ 'total_nqty': fields.Float("Nurse Cost",function="_get_all",function_multi=True),
'total_dcost': fields.Float("Doctor Cost",function="_get_all",function_multi=True),
+ 'total_dqty': fields.Float("Doctor Cost",function="_get_all",function_multi=True),
'total_stcost': fields.Float("Staff Cost",function="_get_all",function_multi=True),
'manual': fields.Boolean("Manual"),
"formulars": fields.One2Many("clinic.labor.cost.formular", "labor_cost_id", "Formulars"),
@@ -280,6 +295,7 @@ class LaborCost(Model):
'categ_id': nurse.categ_id.id,
'rate': rate,
'type': 'nurse',
+ #'qty': qty,
'qty': 1,
}))
@@ -301,7 +317,7 @@ class LaborCost(Model):
'base': 0,
'type': staff.type,
'categ_id': staff.categ_id.id,
- 'level_id': staff.level_id.id,
+ 'level_id': staff.level_id.id, #XXX
'qty': 0,
}
if staff.type!='doctor':
diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py
index ea762e8..706f8a9 100644
--- a/netforce_clinic/models/patient.py
+++ b/netforce_clinic/models/patient.py
@@ -132,6 +132,7 @@ class Patient(Model):
'cycles': fields.One2Many("clinic.patient.cycle","patient_id", "Cycles"),
"vascular_acc": fields.Many2One("clinic.vascular.access","Vascular Ac."),
'state': fields.Selection([['admit','Admit'],['dispose','Dispose']],'State'),
+ 'is_walkin': fields.Boolean("Walk In"),
}
def _get_number(self,context={}):
diff --git a/netforce_clinic/models/report_hd_case_summary.py b/netforce_clinic/models/report_hd_case_summary.py
index 235b8f6..f2fc4b5 100644
--- a/netforce_clinic/models/report_hd_case_summary.py
+++ b/netforce_clinic/models/report_hd_case_summary.py
@@ -53,6 +53,7 @@ class ReportHDCaseSummary(Model):
branch_id=obj.branch_id.id
department_id=obj.department_id.id
date=obj.date
+ crr_month=int(date[5:7]) #XXX
time_start='%s 00:00:00'%obj.date_from
time_stop='%s 23:59:59'%obj.date_to
year=int(date[0:4])
@@ -90,6 +91,7 @@ class ReportHDCaseSummary(Model):
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
+ print('>> dom ', dom)
crr_total=len(get_model("clinic.hd.case").search(dom))
items={}
items['topic%s'%count]={
diff --git a/netforce_clinic/models/report_labor_cost_summary.py b/netforce_clinic/models/report_labor_cost_summary.py
index 5b8552e..499e434 100644
--- a/netforce_clinic/models/report_labor_cost_summary.py
+++ b/netforce_clinic/models/report_labor_cost_summary.py
@@ -16,6 +16,7 @@ class ReportLaborCostSummary(Model):
'staff_id': fields.Many2One("clinic.staff","Staff"),
"staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
'department_id': fields.Many2One("clinic.department","Department"),
+ 'branch_id': fields.Many2One("clinic.branch","Branch"),
'level_id': fields.Many2One("clinic.staff.level","Level"),
'categ_id': fields.Many2One("clinic.staff.categ","Category"),
'only_value': fields.Boolean("Only Amount"),
@@ -56,6 +57,8 @@ class ReportLaborCostSummary(Model):
only_value=res['only_value']
level_id=None
categ_id=None
+ branch_id=None
+ department_id=None
dom=[]
if ids:
obj=self.browse(ids)[0]
@@ -65,6 +68,8 @@ class ReportLaborCostSummary(Model):
staff_type=obj.staff_type
level_id=obj.level_id.id
categ_id=obj.categ_id.id
+ branch_id=obj.branch_id.id
+ department_id=obj.department_id.id
only_value=obj.only_value
dom.append(['date','>=',date_from])
dom.append(['date','<=',date_to])
@@ -76,11 +81,20 @@ class ReportLaborCostSummary(Model):
dom.append(['amount','!=',0])
if categ_id:
dom.append(['staff_id.categ_id','=',categ_id])
+ if branch_id:
+ dom.append(['labor_cost_id.cycle_item_id.branch_id','=',branch_id])
+ if department_id:
+ dom.append(['labor_cost_id.cycle_item_id.department_id','=',department_id])
staffs={}
+ citems={}
+ print('dom ', dom)
+ total_hdcase=0
for line in get_model("clinic.labor.cost.line").search_browse(dom):
lcost=line.labor_cost_id
citem=lcost.cycle_item_id
dpt=citem.department_id
+ qty=line.qty or 0 #XXX
+ total_hdcase+=qty
amt=line.amount or 0
staff=line.staff_id
categ_name=''
@@ -89,13 +103,14 @@ class ReportLaborCostSummary(Model):
level_name=''
if not staff:
continue
- if level_id and staff.level_id.id!=level_id:
+ if level_id and staff.level_id.id !=level_id:
continue
if categ:
categ_id=categ.id
categ_name=categ.name or ""
if staff.level_id:
- level_name=staff.level_id.name or ""
+ level=get_model("clinic.staff.level").browse(staff.level_id.id)
+ level_name=level.name or ""
if not staffs.get(staff.name):
staffs[staff.name]={
'number': staff.number or '',
@@ -106,24 +121,35 @@ class ReportLaborCostSummary(Model):
'categ_id': categ_id,
dpt.name: {
'amt': 0,
+ 'qty': qty,
},
}
if not staffs[staff.name].get(dpt.name):
staffs[staff.name].update({
dpt.name: {
'amt': 0,
+ 'qty': qty,
}})
staffs[staff.name][dpt.name]['amt']+=amt
+ staffs[staff.name][dpt.name]['qty']+=qty
+
+ if not citems.get(citem.id):
+ qty=len([hdcase for hdcase in citem.hd_cases])
+ citems[citem.id]=qty
lines=[]
- dpts=get_model("clinic.department").search_read([],['name'])
+ dom=[]
+ if branch_id:
+ dom.append(['branch_id','=',branch_id])
+ if department_id:
+ dpt_name=get_model('clinic.department').browse(department_id).name
+ dom.append(['name','=',dpt_name])
+ dpts=get_model("clinic.department").search_read(dom,['name'])
dpts=sorted(dpts, key=lambda b: b['name'])
- no=1
staff_types=set()
snames=sorted(staffs.keys()) #sort by staff name
for sname in snames:
vals=staffs[sname]
lvals={
- 'no': no,
'staff_name': sname,
'staff_id': vals.get('staff_id'),
'staff_type': vals.get('staff_type'),
@@ -133,20 +159,24 @@ class ReportLaborCostSummary(Model):
'number': vals.get("number"),
}
total=0
+ total_qty=0
lvals['sub_lines']=[]
for dpt in dpts:
amt=0 #solve bug
+ qty=0
dname=dpt['name'] or ''
vals2=vals.get(dname)
if vals2:
amt=vals2.get("amt",0)
- staff_type=vals2.get("type",'')
- staff_types.update({staff_type})
- lvals['sub_lines'].append({'amt': amt,'dpt_id': dpt['id']})
+ qty=vals2.get("qty",0)
+ _staff_type=vals2.get("type",'')
+ staff_types.update({_staff_type})
+ lvals['sub_lines'].append({'amt': amt,'qty': qty, 'dpt_id': dpt['id']})
total+=amt
+ total_qty+=qty
lvals['total']=total
+ lvals['qty']=qty
lines.append(lvals)
- no+=1
title=''
for stype in list(staff_types):
@@ -156,21 +186,44 @@ class ReportLaborCostSummary(Model):
title+='Nurse'
title=' and'.join(t for t in title.split(" "))
- total_lines=[{'amt': 0} for dpt in dpts]
+ total_lines=[{'amt': 0, 'qty':0} for dpt in dpts]
for line in lines:
i=0
for sub_line in line['sub_lines']:
amt=sub_line['amt'] or 0
+ qty=sub_line['qty'] or 0
total_lines[i]['amt']+=amt
+ total_lines[i]['qty']+=qty
i+=1
total=0
+ total_qty=0
+ total_cost=0
for tline in total_lines:
amt=tline['amt'] or 0
+ qty=tline['qty'] or 0
total+=amt
+ total_cost+=amt
+ total_qty+=qty
total_lines.append({'amt': total})
company_id=get_active_company()
comp=get_model("company").browse(company_id)
+
+ #staff_type=staff_type or staff.type #XXX
+ print("staff_type ", staff_type)
+ if staff_type!='doctor':
+ total_hdcase=0
+ for k,hdcase_qty in citems.items():
+ total_hdcase+=hdcase_qty
+ print("total_hdcase ", total_hdcase)
+
+ # reset no
+ nlines=[]
+ no=1
+ for line in sorted(lines, key=lambda x: x['number']):
+ line['no']=no
+ nlines.append(line)
+ no+=1
data={
'title': title,
'date_from': date_from,
@@ -178,8 +231,10 @@ class ReportLaborCostSummary(Model):
'dpts': dpts,
'comp_name': comp.name or 0,
'comp_span': len(dpts),
- 'lines': sorted(lines, key=lambda x: x['number']),
+ 'lines': nlines,
'total_lines': total_lines,
+ 'total_hdcase': total_hdcase or 0,
+ 'total_cost': total_cost or 0,
}
return data
@@ -197,4 +252,9 @@ class ReportLaborCostSummary(Model):
data['staff_id']=None
return data
+ def onchange_branch(self,context={}):
+ data=context['data']
+ data['department_id']=None
+ return data
+
ReportLaborCostSummary.register()
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index e33607c..40df4af 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -122,12 +122,32 @@ class ClinicSetting(Model):
print("Done!")
return
+ def update_cycle_item_level(self,ids,context={}):
+ for citem in get_model("clinic.cycle.item").search_browse([]):
+ for line in citem.lines:
+ nurse=line.nurse_id
+ if nurse.level_id:
+ line.write({
+ 'level_id': nurse.level_id.id,
+ })
+
def run_script(self,ids,context={}):
user_id=get_active_user()
if user_id !=1:
print("Only admin!!")
return
+ #obj=self.browse(ids)[0]
+ #obj.update_staff_department()
+ #obj.remove_rotation()
+ #obj.update_staff_level()
+ #obj.update_cycle_item_level()
+ for st in get_model("clinic.staff").search_browse([]):
+ st.write({
+ 'note': ' ',
+ })
print("Done!")
+ return
+
lines=[]
for pt in get_model("clinic.patient").search_browse([['state','=','admit']]):
partner_id=None
@@ -173,7 +193,7 @@ class ClinicSetting(Model):
print("Done!")
return
- def udpate_staff_level(self,ids,context={}):
+ def update_staff_level(self,ids,context={}):
user_id=get_active_user()
if user_id !=1:
print("Only admin!!")
diff --git a/netforce_clinic/models/staff.py b/netforce_clinic/models/staff.py
index f0b9683..bc441d2 100644
--- a/netforce_clinic/models/staff.py
+++ b/netforce_clinic/models/staff.py
@@ -129,13 +129,13 @@ class Staff(Model):
"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",function="_get_rotation",function_multi=True),
- 'level_id': fields.Many2One("clinic.staff.level", "Level", function="_get_rotation",function_multi=True),
+ 'categ_id': fields.Many2One("clinic.staff.categ", "Category",function="_get_rotation",function_multi=True,store=True),
+ 'level_id': fields.Many2One("clinic.staff.level", "Level", function="_get_rotation",function_multi=True,store=True),
'active': fields.Boolean("Active"),
'date': fields.Date("Register Date"),
- 'wage': fields.Float("Wage", function="_get_rotation",function_multi=True),
- 'max_cycle': fields.Integer("Max Cycle", function="_get_rotation",function_multi=True),
- 'ot_per_cycle': fields.Integer("OT Per Cycle", function="_get_rotation",function_multi=True),
+ 'wage': fields.Float("Wage", function="_get_rotation",function_multi=True,store=True),
+ 'max_cycle': fields.Integer("Max Cycle", function="_get_rotation",function_multi=True,store=True),
+ 'ot_per_cycle': fields.Integer("OT Per Cycle", function="_get_rotation",function_multi=True,store=True),
'check_max_cycle': fields.Boolean("Check Max Cycle"),
'hire_date': fields.Date("Hire Date"),
'resign_date': fields.Date("Resign Date"),
diff --git a/netforce_clinic/templates/report_labor_cost_summary.hbs b/netforce_clinic/templates/report_labor_cost_summary.hbs
index 281c0bb..10d0957 100644
--- a/netforce_clinic/templates/report_labor_cost_summary.hbs
+++ b/netforce_clinic/templates/report_labor_cost_summary.hbs
@@ -1,6 +1,13 @@
-
+
+
+
+
+ HD Case: {{total_hdcase}}
+ Cost : ฿{{currency total_cost zero=""}}
+ |
+
|
|
@@ -20,7 +27,7 @@
{{name}} |
{{/each}}
- รวม |
+ รายได้ |
@@ -53,6 +60,5 @@
{{#each total_lines}}
{{currency amt zero=""}} |
{{/each}}
- |
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt
index c03c81d..e85ecd7 100644
--- a/netforce_clinic/todo.txt
+++ b/netforce_clinic/todo.txt
@@ -2,6 +2,21 @@ todo:
- multi department access ***
- merge staff same name but different department
- doctor นายแพทย์ ทวีชัย
+ - tick
+ 1. create profile for all department + branch (2)
+ - create sharing setting for all model
+ - branch
+ - deparment
+ - patient
+ - patient cycle
+ - cycle item
+ - visit
+ - hd case
+ - dialyzer
+ - shop
+ - sickbed
+ - staff
+ - staff rotation : only manager nurse
- run script
- update level's nurse
- report k. boy (sub detail) -> ok