115 lines
3.7 KiB
Python
115 lines
3.7 KiB
Python
import time
|
|
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 ReportHDCaseSummaryV2(Model):
|
|
_name="report.hdcase.summary"
|
|
_trasient=True
|
|
|
|
_fields={
|
|
"month": fields.Date("Month"),
|
|
"branch_id": fields.Many2One("clinic.branch","Branch"),
|
|
"department_id": fields.Many2One("clinic.department","Department"),
|
|
}
|
|
|
|
def default_get(self,field_names=None,context={},**kw):
|
|
vals={
|
|
"month": time.strftime("%Y-%m-%d"),
|
|
}
|
|
select_dpt=get_model('select.company').get_select()
|
|
if select_dpt:
|
|
vals.update({
|
|
"branch_id": select_dpt['branch_id'],
|
|
"department_id": select_dpt['department_id'],
|
|
})
|
|
return vals
|
|
|
|
def get_report_data(self, ids, context={}):
|
|
user_id=get_active_user()
|
|
user=get_model('base.user').browse(user_id)
|
|
defaults=self.default_get(context=context)
|
|
month=defaults.get("month")
|
|
y,m,d=month.split("-")
|
|
branch_id=defaults.get("branch_id")
|
|
department_id=defaults.get("department_id")
|
|
|
|
if ids:
|
|
obj=self.browse(ids)[0]
|
|
branch_id=obj.branch_id.id
|
|
department_id=obj.department_id.id
|
|
month=obj.month
|
|
y,m,d=month.split("-")
|
|
|
|
#auto gen at the fist time of that month
|
|
get_model("clinic.patient.move").auto_get_data(date=month, department_id=department_id)
|
|
|
|
crr_month=m
|
|
weekday, total_day=monthrange(int(y), int(m))
|
|
date_from="-".join([y,m,"01"])
|
|
date_to="-".join([y,m,str(total_day)])
|
|
|
|
cond=[
|
|
['date','>=',date_from],
|
|
['date','<=',date_to],
|
|
['state','in',["waiting_payment","paid"]],
|
|
|
|
]
|
|
#if branch_id:
|
|
#cond.append([
|
|
#'branch_id','=',branch_id,
|
|
#])
|
|
if department_id:
|
|
cond.append([
|
|
'department_id','=',department_id,
|
|
])
|
|
|
|
hdcase_ids=get_model("clinic.hd.case").search(cond)
|
|
|
|
company_id=get_active_company()
|
|
company=get_model("company").browse(company_id)
|
|
department=get_model("clinic.department").browse(department_id)
|
|
|
|
year_thai=utils.date2thai(month, lang='th_TH').split("-")[0]
|
|
month_thai=utils.MONTHS['th_TH'][int(crr_month)]
|
|
|
|
context['defaults']={
|
|
'date': date_from,
|
|
'date_from': date_from,
|
|
'date_to': date_to,
|
|
'branch_id': branch_id,
|
|
'department_id': department_id,
|
|
}
|
|
medicals=get_model("clinic.report.medical.summary").get_report_data(ids=[],context=context)
|
|
medical_lines=medicals['lines']
|
|
medical_titles=medicals['titles']
|
|
|
|
data={
|
|
'company_name': company.name,
|
|
'department_name': department.name,
|
|
'month_thai': month_thai,
|
|
'year_thai': year_thai,
|
|
'total_hdcase': len(hdcase_ids),
|
|
'medicals': medical_lines,
|
|
'titles': medical_titles,
|
|
'date': month,
|
|
'can_edit': False,
|
|
'date_print': time.strftime("%Y-%m-%d %H:%M:%S"),
|
|
'user_name': user.name,
|
|
}
|
|
#TODO separate next month by patient type
|
|
data2=get_model("clinic.patient.move").get_data(date=month, department_id=department_id)
|
|
data.update(data2)
|
|
|
|
res=get_model("permission").search([['code','=','hdcase_report_admin']])
|
|
if res or user_id==1:
|
|
data.update({
|
|
'can_edit': True,
|
|
})
|
|
return data
|
|
|
|
ReportHDCaseSummaryV2.register()
|