clinic/netforce_clinic/models/report_staff.py

88 lines
2.9 KiB
Python
Raw Permalink Normal View History

2015-02-02 11:12:00 +00:00
from netforce.model import Model, fields, get_model
2015-01-30 11:15:13 +00:00
class ReportStaff(Model):
_name='clinic.report.staff'
_string="Report Staff"
def _get_store(self,ids,context={}):
res={}
for obj in self.browse(ids):
2015-02-03 05:09:30 +00:00
htotal=len(obj.lines)
ptotal=len(obj.patients)
2015-01-30 11:15:13 +00:00
res[obj.id]={
2015-02-03 05:09:30 +00:00
'name': htotal or ptotal,
2015-01-30 11:15:13 +00:00
}
return res
def _get_all(self,ids,context={}):
res={}
for obj in self.browse(ids):
2015-02-02 10:35:47 +00:00
htotal=len(obj.lines)
ptotal=len(obj.patients)
2015-01-30 11:15:13 +00:00
res[obj.id]={
2015-02-02 10:35:47 +00:00
'hdcase_total': htotal,
'patient_total': ptotal,
2015-01-30 11:15:13 +00:00
}
return res
_fields={
2015-02-02 10:35:47 +00:00
'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),
2015-01-30 11:15:13 +00:00
'name': fields.Char("Name", function="_get_store",function_multi=True,store=True),
2015-02-02 10:35:47 +00:00
'date_from': fields.Date("From",search=True),
2015-01-30 11:15:13 +00:00
'date_to': fields.Date("To"),
2015-02-02 10:35:47 +00:00
'hdcase_total': fields.Char("HDCase Total", function="_get_all",function_multi=True),
'patient_total': fields.Char("Patient Total", function="_get_all",function_multi=True),
2015-01-30 11:15:13 +00:00
'lines': fields.One2Many("clinic.report.staff.line","report_staff_id","Lines"),
2015-02-02 10:35:47 +00:00
'patients': fields.One2Many("clinic.report.staff.patient","report_staff_id","Patient Lines"),
2015-01-30 11:15:13 +00:00
}
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)
2015-02-02 10:35:47 +00:00
def get_data(self,context={}):
2015-02-02 11:12:00 +00:00
refer_id=int(context.get("refer_id","0"))
obj=get_model('clinic.report.staff').browse(refer_id)
lines=[]
2015-02-03 05:09:30 +00:00
count=1
2015-02-02 11:12:00 +00:00
for line in obj.lines:
patient=line.patient_id
hd_case=line.hd_case_id
2015-02-03 05:09:30 +00:00
amount=line.amount or 0
2015-02-02 11:12:00 +00:00
lines.append({
'no': count,
2015-02-03 05:09:30 +00:00
'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,
2015-02-02 11:12:00 +00:00
})
count+=1
data={
'date_from': obj.date_from,
'date_to': obj.date_to,
'staff_name': obj.staff_id.name or '',
2015-02-03 05:09:30 +00:00
'lines': lines, # is doctor
'patients': patients,
2015-02-02 11:12:00 +00:00
}
2015-02-02 10:35:47 +00:00
return data
2015-01-30 11:15:13 +00:00
ReportStaff.register()