report staff fee
parent
f9042fb5f4
commit
93fbd6c64b
|
@ -6,7 +6,7 @@ from netforce.access import get_active_company
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
||||||
class ReportStaffFee(Model):
|
class ReportStaffFeeDetail(Model):
|
||||||
_name="clinic.report.staff.fee"
|
_name="clinic.report.staff.fee"
|
||||||
_string="Report Staff Fee"
|
_string="Report Staff Fee"
|
||||||
_transient=True
|
_transient=True
|
||||||
|
@ -16,6 +16,7 @@ class ReportStaffFee(Model):
|
||||||
"date_from": fields.Date("From", required=True),
|
"date_from": fields.Date("From", required=True),
|
||||||
"date_to": fields.Date("To", required=True),
|
"date_to": fields.Date("To", required=True),
|
||||||
'staff_id': fields.Many2One("clinic.staff","Staff"),
|
'staff_id': fields.Many2One("clinic.staff","Staff"),
|
||||||
|
"type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
|
||||||
'department_id': fields.Many2One("clinic.department","Department"),
|
'department_id': fields.Many2One("clinic.department","Department"),
|
||||||
'branch_id': fields.Many2One("clinic.branch","Branch"),
|
'branch_id': fields.Many2One("clinic.branch","Branch"),
|
||||||
}
|
}
|
||||||
|
@ -49,31 +50,74 @@ class ReportStaffFee(Model):
|
||||||
time_start='%s-%s-01'%(year,str(month).zfill(2))
|
time_start='%s-%s-01'%(year,str(month).zfill(2))
|
||||||
time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day)
|
time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day)
|
||||||
staff_id=None
|
staff_id=None
|
||||||
department_id=None
|
staff_type=None
|
||||||
branch_id=None
|
department=None
|
||||||
|
branch=None
|
||||||
if ids:
|
if ids:
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
month=obj.date_from.split("-")[1]
|
month=obj.date_from.split("-")[1]
|
||||||
time_start=obj.date_from
|
time_start=obj.date_from
|
||||||
time_stop=obj.date_to
|
time_stop=obj.date_to
|
||||||
staff_id=obj.staff_id.id
|
staff_id=obj.staff_id.id
|
||||||
department_id=obj.department_id.id
|
staff_type=obj.type
|
||||||
branch_id=obj.branch_id.id
|
department=obj.department_id
|
||||||
|
branch=obj.branch_id
|
||||||
# new patient of this month
|
# new patient of this month
|
||||||
dom=[]
|
dom=[]
|
||||||
dom.append(['date','>=',time_start])
|
dom.append(['date','>=',time_start])
|
||||||
dom.append(['date','<=',time_stop])
|
dom.append(['date','<=',time_stop])
|
||||||
if department_id:
|
if department:
|
||||||
dom.append(['department_id','=',department_id])
|
dom.append(['staff_id.department_id','=',department.id])
|
||||||
if branch_id:
|
if branch:
|
||||||
dom.append(['branch_id','=',branch_id])
|
dom.append(['staff_id.branch_id','=',branch.id])
|
||||||
|
if staff_type:
|
||||||
|
dom.append(['staff_id.type','=',staff_type])
|
||||||
staff_name=''
|
staff_name=''
|
||||||
# TODO can filter doctor and nurse
|
|
||||||
if staff_id:
|
if staff_id:
|
||||||
staff=get_model("clinic.staff").browse(staff_id)
|
staff=get_model("clinic.staff").browse(staff_id)
|
||||||
staff_name=staff.name
|
staff_name=staff.name
|
||||||
dom.append(['staff_id','=',staff.id])
|
dom.append(['staff_id','=',staff.id])
|
||||||
dlines=get_model('clinic.labor.cost.line').search_browse(dom)
|
dlines=get_model('clinic.labor.cost.line').search_browse(dom)
|
||||||
|
# group by date
|
||||||
|
all_vals={}
|
||||||
|
for dline in dlines:
|
||||||
|
date=dline.date
|
||||||
|
staff=dline.staff_id
|
||||||
|
dpt=staff.department_id
|
||||||
|
brch=staff.branch_id
|
||||||
|
key=(date,staff.id)
|
||||||
|
if key not in all_vals.keys():
|
||||||
|
all_vals[key]={
|
||||||
|
'qty': 0,
|
||||||
|
'staff_type': utils.STAFF_TYPE.get(staff.type,''),
|
||||||
|
'staff_name': staff.name or "",
|
||||||
|
'staff_id': staff.id,
|
||||||
|
'branch_name': brch.name or '',
|
||||||
|
'department_name': dpt.name or '',
|
||||||
|
'amount': 0,
|
||||||
|
}
|
||||||
|
all_vals[key]['qty']+=dline.qty or 0
|
||||||
|
all_vals[key]['amount']+=dline.amount or 0
|
||||||
|
|
||||||
|
lines=[]
|
||||||
|
total_amount=0.0
|
||||||
|
total_qty=0.0
|
||||||
|
for key,vals in all_vals.items():
|
||||||
|
date,staff_id=key
|
||||||
|
qty=vals['qty'] or 0
|
||||||
|
amount=vals['amount'] or 0
|
||||||
|
lines.append({
|
||||||
|
'date': date,
|
||||||
|
'qty': qty,
|
||||||
|
'staff_id': vals['staff_id'],
|
||||||
|
'staff_type': vals['staff_type'],
|
||||||
|
'staff_name': vals['staff_name'],
|
||||||
|
'department_name': vals['department_name'],
|
||||||
|
'branch_name': vals['branch_name'],
|
||||||
|
'amount': amount or 0.0,
|
||||||
|
})
|
||||||
|
total_qty+=qty
|
||||||
|
total_amount+=amount
|
||||||
|
|
||||||
month_str=utils.MONTHS['th_TH'][int(month)]
|
month_str=utils.MONTHS['th_TH'][int(month)]
|
||||||
start=int(time_start[8:10])
|
start=int(time_start[8:10])
|
||||||
|
@ -84,6 +128,8 @@ class ReportStaffFee(Model):
|
||||||
'parent_company_name': company.parent_id.name or "",
|
'parent_company_name': company.parent_id.name or "",
|
||||||
'staff_name': staff_name,
|
'staff_name': staff_name,
|
||||||
'lines': sorted(lines,key=lambda x: x['date']),
|
'lines': sorted(lines,key=lambda x: x['date']),
|
||||||
|
'total_qty': total_qty,
|
||||||
|
'total_amount': total_amount,
|
||||||
'month': month_str,
|
'month': month_str,
|
||||||
'from': time_start,
|
'from': time_start,
|
||||||
'to': time_stop,
|
'to': time_stop,
|
||||||
|
@ -101,4 +147,4 @@ class ReportStaffFee(Model):
|
||||||
data['date_to']="%s-%s-%s"%(year,month,total_day)
|
data['date_to']="%s-%s-%s"%(year,month,total_day)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
ReportStaffFee.register()
|
ReportStaffFeeDetail.register()
|
||||||
|
|
|
@ -32,10 +32,12 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{date}}</td>
|
<td>{{date}}</td>
|
||||||
{{#unless ../staff_name}}
|
{{#unless ../staff_name}}
|
||||||
<td>{{staff_name}}</td>
|
<td>
|
||||||
|
{{view "link" string=staff_name action="clinic_staff" action_options="mode=form" active_id=staff_id}}
|
||||||
|
</td>
|
||||||
<td>{{staff_type}}</td>
|
<td>{{staff_type}}</td>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
<td style="text-align:right">{{dpt_name}}</td>
|
<td style="text-align:right">{{department_name}}</td>
|
||||||
<td style="text-align:right">{{branch_name}}</td>
|
<td style="text-align:right">{{branch_name}}</td>
|
||||||
<td style="text-align:right">{{qty}}</td>
|
<td style="text-align:right">{{qty}}</td>
|
||||||
<td style="text-align:right">{{currency amount}}</td>
|
<td style="text-align:right">{{currency amount}}</td>
|
||||||
|
|
Loading…
Reference in New Issue