clinic/netforce_clinic/models/report_hd_medical.py

76 lines
2.1 KiB
Python

import time
from datetime import datetime
from calendar import monthrange
from netforce.model import Model,fields,get_model
class ReportHDMedical(Model):
_name="clinic.report.hd.medical"
_string="Hemodialysis Report Medical Summary"
_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={}):
for item in get_model("company").search_browse([]):
company_name=item.name
date=datetime.now().strftime("%Y-%m-%d")
#datemonth=datetime.now().strftime("%m")
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")
#dom=[]
#dom.append(['fee_type','=','mg'])
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)
dom=[]
dom.append(['state','=','completed'])
dom.append(['time_start','>=',time_start])
dom.append(['time_stop','<=',time_stop])
lines=[]
index=0
for product in get_model("product").search_browse(['type','=','stock']):
product_id=product.id or ""
product_code=product.code or ""
product_name=product.name or ""
product_amount=len(str(product_code))
#total=len(str(product_amount))
index+=1
vals={
'product_code' : product_code,
'medical' : product_name,
'uc' : '-',
'buy' : '-',
'amount' : product_amount,
'product_id': product_id,
}
lines.append(vals)
data={
'month': month_str,
'year': year,
'lines': lines,
'company_name': company_name,
}
return data
ReportHDMedical.register()