clinic/netforce_clinic/models/report_hd_monthly.py

51 lines
1.4 KiB
Python

import time
from datetime import datetime
from calendar import monthrange
from netforce.model import Model, fields, get_model
class HDReportMonth(Model):
_name="clinic.hd.report.monthly"
_string="Summary of the Hemodialysis"
_transient=True
_fields={
"date": fields.Date("Month", required=True),
}
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
}
def get_report_data(self,ids,context={}):
if not ids:
return {}
obj=self.browse(ids)[0]
year=int(obj.date[0:3])
month=int(obj.date[5:7])
month_str=datetime.strptime(obj.date,'%Y-%m-%d').strftime("%B")
weekday, total_day=monthrange(year, month)
time_start='2014-%s-01 00:00:00'%(month)
time_stop='2014-%s-%s 23:59:59'%(month,total_day)
lines=[]
dom=[]
dom.append(['state','=','completed'])
dom.append(['time_start','>=',time_start])
dom.append(['time_stop','<=',time_stop])
hd_cases=get_model("clinic.hd.case").search_browse(dom)
print("="*50)
for hd_case in hd_cases:
lines.append({
'topic': 'The number of times the Hemodialysis',
'month': month_str,
'amount': len(hd_cases),
})
data={
'lines': lines,
}
return data
HDReportMonth.register()