clinic/netforce_clinic/models/report_discontinue_patient.py

67 lines
1.9 KiB
Python
Raw Normal View History

2014-11-05 06:45:28 +00:00
import time
2014-11-10 11:33:01 +00:00
from calendar import monthrange
2014-11-05 06:45:28 +00:00
from netforce.model import Model,fields,get_model
2014-11-05 07:03:12 +00:00
from netforce.access import get_active_company
2014-11-05 06:45:28 +00:00
2014-11-10 11:33:01 +00:00
from . import utils
2014-11-05 06:45:28 +00:00
class ReportDiscontinuePatient(Model):
_name="clinic.report.discontinue.patient"
_string="Report Discontinue Patient"
_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={}):
2014-11-05 07:03:12 +00:00
company_id=get_active_company()
company=get_model('company').browse(company_id)
2014-11-10 11:33:01 +00:00
year, month=time.strftime("%Y-%m").split("-")
2014-11-10 14:52:47 +00:00
defaults=context.get('defaults')
if defaults:
year,month,day=defaults['date'].split("-")
2014-11-10 11:33:01 +00:00
if ids:
obj=self.browse(ids)[0]
year,month,day=obj.date.split("-")
# new patient of this month
year=int(year)
month=int(month)
dom=[]
weekday, total_day=monthrange(year, month)
dom=[]
time_start='%s-%s-01'%(year,str(month).zfill(2))
time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day)
dom.append(['resign_date','>=',time_start])
dom.append(['resign_date','<=',time_stop])
dom.append(['active','=',False])
records=get_model('clinic.patient').search_browse(dom)
lines=[]
no=1
for record in records:
lines.append({
'no': no,
'pid': record.id,
'name': record.name or '',
'note': record.note or '',
})
no+=1
month_str=utils.MONTHS['th_TH'][month]
2014-11-05 07:03:12 +00:00
data={
'company_name': company.name or "",
'parent_company_name': company.parent_id.name or "",
2014-11-10 11:33:01 +00:00
'lines': lines,
'month': month_str,
'year': year,
2014-11-05 07:03:12 +00:00
}
2014-11-10 11:33:01 +00:00
2014-11-05 06:45:28 +00:00
return data
ReportDiscontinuePatient.register()