105 lines
3.6 KiB
Python
105 lines
3.6 KiB
Python
|
import time
|
||
|
from calendar import monthrange
|
||
|
|
||
|
from netforce.model import Model,fields,get_model
|
||
|
from netforce.access import get_active_company
|
||
|
|
||
|
from . import utils
|
||
|
|
||
|
class ReportStaffFee(Model):
|
||
|
_name="clinic.report.staff.fee"
|
||
|
_string="Report Staff Fee"
|
||
|
_transient=True
|
||
|
|
||
|
_fields={
|
||
|
"date": fields.Date("Month"),
|
||
|
"date_from": fields.Date("From", required=True),
|
||
|
"date_to": fields.Date("To", required=True),
|
||
|
'staff_id': fields.Many2One("clinic.staff","Staff"),
|
||
|
'department_id': fields.Many2One("clinic.department","Department"),
|
||
|
'branch_id': fields.Many2One("clinic.branch","Branch"),
|
||
|
}
|
||
|
|
||
|
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)
|
||
|
|
||
|
_defaults={
|
||
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
||
|
'date_from': _get_date_from,
|
||
|
'date_to': _get_date_to,
|
||
|
}
|
||
|
|
||
|
def get_report_data(self,ids,context={}):
|
||
|
company_id=get_active_company()
|
||
|
company=get_model('company').browse(company_id)
|
||
|
year, month=time.strftime("%Y-%m").split("-")
|
||
|
weekday, total_day=monthrange(int(year), int(month))
|
||
|
time_start='%s-%s-01'%(year,str(month).zfill(2))
|
||
|
time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day)
|
||
|
|
||
|
defaults=context.get('defaults')
|
||
|
if defaults:
|
||
|
year,month,day=defaults['date'].split("-")
|
||
|
time_start='%s-%s-01'%(year,str(month).zfill(2))
|
||
|
time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day)
|
||
|
staff_id=None
|
||
|
department_id=None
|
||
|
branch_id=None
|
||
|
if ids:
|
||
|
obj=self.browse(ids)[0]
|
||
|
month=obj.date_from.split("-")[1]
|
||
|
time_start=obj.date_from
|
||
|
time_stop=obj.date_to
|
||
|
staff_id=obj.staff_id.id
|
||
|
department_id=obj.department_id.id
|
||
|
branch_id=obj.branch_id.id
|
||
|
# new patient of this month
|
||
|
dom=[]
|
||
|
dom.append(['date','>=',time_start])
|
||
|
dom.append(['date','<=',time_stop])
|
||
|
if department_id:
|
||
|
dom.append(['department_id','=',department_id])
|
||
|
if branch_id:
|
||
|
dom.append(['branch_id','=',branch_id])
|
||
|
staff_name=''
|
||
|
# TODO can filter doctor and nurse
|
||
|
if staff_id:
|
||
|
staff=get_model("clinic.staff").browse(staff_id)
|
||
|
staff_name=staff.name
|
||
|
dom.append(['staff_id','=',staff.id])
|
||
|
dlines=get_model('clinic.labor.cost.line').search_browse(dom)
|
||
|
|
||
|
month_str=utils.MONTHS['th_TH'][int(month)]
|
||
|
start=int(time_start[8:10])
|
||
|
stop=int(time_stop[8:10])
|
||
|
diff=stop-start
|
||
|
data={
|
||
|
'company_name': company.name or "",
|
||
|
'parent_company_name': company.parent_id.name or "",
|
||
|
'staff_name': staff_name,
|
||
|
'lines': sorted(lines,key=lambda x: x['date']),
|
||
|
'month': month_str,
|
||
|
'from': time_start,
|
||
|
'to': time_stop,
|
||
|
'is_duration': diff+1 < total_day,
|
||
|
'year': year,
|
||
|
}
|
||
|
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
|
||
|
|
||
|
ReportStaffFee.register()
|