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 from . import utils class HDCaseDialy(Model): _name="clinic.hd.case.dialy" _string="HD Case Dialy" _transient=True _fields={ "date": fields.Date("Date", required=True), } _defaults={ 'date': lambda *a: time.strftime("%Y-%m-%d"), } 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") if ids: obj=self.browse(ids)[0] date=obj.date month=int(date[5:7]) day=date[8:10] year=date[0:4] month_str=utils.MONTHS['th_TH'][month] dom=[] dom.append(['time_start','>=','%s 00:00:00'%date]) dom.append(['time_stop','<=','%s 23:59:59'%date]) lines=[] no=1 for obj in get_model("clinic.hd.case").search_browse(dom): patient_type=utils.PATIENT_TYPE[obj.patient_id.type] dlz_number="" dlz_id=None for line in obj.dialyzers: dlz=line.dialyzer_id dlz_id=dlz.id dlz_number=dlz.number line={ 'cycle_name': obj.cycle_id.name, 'no': no, 'hd_case_number': obj.number, 'patient_name': obj.patient_id.name, 'patient_type': patient_type, 'doctor_name': obj.doctor_id.name, 'doctor_id': obj.doctor_id.id, 'fee_amount': obj.fee_amount, 'hd_case_id': obj.id, 'dlz_number': dlz_number, 'dlz_id': dlz_id, 'success_color': obj.state=='completed' and '#99ff99' or '', 'note': obj.note or "", } lines.append(line) no+=1 # XXX year=int(year)+543 date_str='%s %s %s'%(day,month_str,year) data={ 'lines': lines, 'date': date_str, 'company_name': company.name, 'company_parent_name': company.parent_id.name, } return data HDCaseDialy.register()