clinic/netforce_clinic/models/report_hd_monthly.py

53 lines
1.5 KiB
Python

import time
from datetime import datetime
from calendar import monthrange
from netforce.model import Model, fields, get_model
class ReportHDMonthly(Model):
_name="clinic.report.hd.monthly"
_string="Report HD Monthly"
_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={}):
date=datetime.now().strftime("%Y-%m-%d")
if ids:
obj=self.browse(ids)[0]
date=obj.date
year=int(date[0:4])
month=int(date[5:7])
month_str=datetime.strptime(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)
for hd_case in hd_cases:
lines.append({
'topic': 'The number of times the Hemodialysis',
'month': month_str,
'amount': len(hd_cases),
})
data={
'month': month_str,
'year': year,
'lines': lines,
}
return data
ReportHDMonthly.register()