clinic/netforce_clinic/models/report_hdcase_summary.py

102 lines
3.3 KiB
Python

import time
import urllib.parse as urllib
from datetime import datetime
from calendar import monthrange
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company, get_active_user
from . import utils
class ReportHDCaseSummary(Model):
_name="report.hdcase.summary"
_string="Report HDCase Summary"
_transient=True
_fields={
"date": fields.Date("Month", required=True),
"date_from": fields.Date("From", required=True),
"date_to": fields.Date("To", required=True),
'branch_id': fields.Many2One("clinic.branch","Branch"),
'department_id': fields.Many2One("clinic.department","Departments"),
'hdcase_type': fields.Selection([['completed','Completed'],['not_completed','Not Completed']],"HDCase Type"),
}
def _get_date_from(self,context={}):
year,month=time.strftime("%Y-%m").split("-")
return '%s-%s-01'%(year,month)
def _get_date_to(self,context={}):
year,month,day=time.strftime("%Y-%m-%d").split("-")
weekday, total_day=monthrange(int(year), int(month))
return "%s-%s-%s"%(year,month,total_day)
def _get_branch(self,context={}):
res=get_model('select.company').get_select()
if res:
return res['branch_id']
def _get_department(self,context={}):
res=get_model('select.company').get_select()
if res:
if res.get("department_ids"):
return res['department_ids'][0]
else:
return res['department_id']
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
'date_from': _get_date_from,
'date_to': _get_date_to,
'branch_id': _get_branch,
'department_id': _get_department,
'hdcase_type': 'completed',
}
def get_report_data(self,ids,context={}):
company_id=get_active_company()
company=get_model("company").browse(company_id)
date=datetime.now().strftime("%Y-%m-%d")
year=int(date[0:4])
crr_month=int(date[5:7])
weekday, crr_total_day=monthrange(year, crr_month)
defaults=self.default_get(context=context)
date_from=defaults.get('date_from',date)
date_to=defaults.get('date_to',date)
branch_id=defaults.get("branch_id",None)
department_id=defaults.get("department_id",None)
hdcase_type=defaults.get('hdcase_type','completed')
#TODO get data from clinic.patient.move
#DO SOME STAFF
data={}
return data
def onchange_date(self,context={}):
data=context['data']
date=data['date']
year,month,day=date.split("-")
weekday, total_day=monthrange(int(year), int(month))
data['date_from']="%s-%s-01"%(year,month)
data['date_to']="%s-%s-%s"%(year,month,total_day)
return data
def onchange_branch(self,context={}):
data=context['data']
data['department_id']=None
return data
def run_report(self,ids,context={}):
return {
'next': {
'name': 'clinic_print_hd_case_summary',
'refer_id': ids[0],
'action_options': 'convert=pdf',
}
}
def export_pdf(self,ids,context={}):
raise Exception("TODO")
return
ReportHDCaseSummary.register()