clinic/netforce_clinic/models/report_staff.py

88 lines
2.9 KiB
Python

from netforce.model import Model, fields, get_model
class ReportStaff(Model):
_name='clinic.report.staff'
_string="Report Staff"
def _get_store(self,ids,context={}):
res={}
for obj in self.browse(ids):
htotal=len(obj.lines)
ptotal=len(obj.patients)
res[obj.id]={
'name': htotal or ptotal,
}
return res
def _get_all(self,ids,context={}):
res={}
for obj in self.browse(ids):
htotal=len(obj.lines)
ptotal=len(obj.patients)
res[obj.id]={
'hdcase_total': htotal,
'patient_total': ptotal,
}
return res
_fields={
'entry_id': fields.Many2One("clinic.labor.cost.entry",'Labor Cost Entry',search=True),
'staff_id': fields.Many2One("clinic.staff",'Staff',search=True),
"staff_type": fields.Selection([['staff','Staff'],["doctor","Doctor"],["nurse","Nurse"]],"Type",search=True),
'name': fields.Char("Name", function="_get_store",function_multi=True,store=True),
'date_from': fields.Date("From",search=True),
'date_to': fields.Date("To"),
'hdcase_total': fields.Char("HDCase Total", function="_get_all",function_multi=True),
'patient_total': fields.Char("Patient Total", function="_get_all",function_multi=True),
'lines': fields.One2Many("clinic.report.staff.line","report_staff_id","Lines"),
'patients': fields.One2Many("clinic.report.staff.patient","report_staff_id","Patient Lines"),
}
def create(self,vals,**kw):
id=super().create(vals,**kw)
self.function_store([id])
return id
def write(self,ids,vals,**kw):
super().write(ids,vals,**kw)
self.function_store(ids)
def get_data(self,context={}):
refer_id=int(context.get("refer_id","0"))
obj=get_model('clinic.report.staff').browse(refer_id)
lines=[]
count=1
for line in obj.lines:
patient=line.patient_id
hd_case=line.hd_case_id
amount=line.amount or 0
lines.append({
'no': count,
'date': line.date,
'hd_case_name': hd_case.number,
'patient_name': patient.name or '',
'amount': amount
})
count+=1
count=1
patients=[]
for pt in obj.patients:
patient=pt.patient_id
amount=pt.amount or 0
patients.append({
'no': count,
'patient_name': patient.name or '',
'amount': amount,
})
count+=1
data={
'date_from': obj.date_from,
'date_to': obj.date_to,
'staff_name': obj.staff_id.name or '',
'lines': lines, # is doctor
'patients': patients,
}
return data
ReportStaff.register()