clinic/netforce_clinic/models/report_hd_monthly.py

51 lines
1.4 KiB
Python
Raw Normal View History

2014-10-15 11:46:19 +00:00
import time
2014-10-15 12:39:21 +00:00
from datetime import datetime
from calendar import monthrange
2014-10-15 11:46:19 +00:00
2014-10-15 12:39:21 +00:00
from netforce.model import Model, fields, get_model
2014-10-15 11:46:19 +00:00
class HDReportMonth(Model):
_name="clinic.hd.report.monthly"
_string="Summary of the Hemodialysis"
_transient=True
_fields={
2014-10-15 12:39:21 +00:00
"date": fields.Date("Month", required=True),
2014-10-15 11:46:19 +00:00
}
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
}
def get_report_data(self,ids,context={}):
2014-10-15 12:39:21 +00:00
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,
}
2014-10-15 11:46:19 +00:00
return data
2014-10-15 12:39:21 +00:00
2014-10-15 11:46:19 +00:00
HDReportMonth.register()