report staff fee
parent
f9042fb5f4
commit
93fbd6c64b
|
@ -6,7 +6,7 @@ from netforce.access import get_active_company
|
|||
|
||||
from . import utils
|
||||
|
||||
class ReportStaffFee(Model):
|
||||
class ReportStaffFeeDetail(Model):
|
||||
_name="clinic.report.staff.fee"
|
||||
_string="Report Staff Fee"
|
||||
_transient=True
|
||||
|
@ -16,6 +16,7 @@ class ReportStaffFee(Model):
|
|||
"date_from": fields.Date("From", required=True),
|
||||
"date_to": fields.Date("To", required=True),
|
||||
'staff_id': fields.Many2One("clinic.staff","Staff"),
|
||||
"type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
|
||||
'department_id': fields.Many2One("clinic.department","Department"),
|
||||
'branch_id': fields.Many2One("clinic.branch","Branch"),
|
||||
}
|
||||
|
@ -49,32 +50,75 @@ class ReportStaffFee(Model):
|
|||
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
|
||||
staff_type=None
|
||||
department=None
|
||||
branch=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
|
||||
staff_type=obj.type
|
||||
department=obj.department_id
|
||||
branch=obj.branch_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])
|
||||
if department:
|
||||
dom.append(['staff_id.department_id','=',department.id])
|
||||
if branch:
|
||||
dom.append(['staff_id.branch_id','=',branch.id])
|
||||
if staff_type:
|
||||
dom.append(['staff_id.type','=',staff_type])
|
||||
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)
|
||||
|
||||
# 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)]
|
||||
start=int(time_start[8:10])
|
||||
stop=int(time_stop[8:10])
|
||||
|
@ -84,6 +128,8 @@ class ReportStaffFee(Model):
|
|||
'parent_company_name': company.parent_id.name or "",
|
||||
'staff_name': staff_name,
|
||||
'lines': sorted(lines,key=lambda x: x['date']),
|
||||
'total_qty': total_qty,
|
||||
'total_amount': total_amount,
|
||||
'month': month_str,
|
||||
'from': time_start,
|
||||
'to': time_stop,
|
||||
|
@ -101,4 +147,4 @@ class ReportStaffFee(Model):
|
|||
data['date_to']="%s-%s-%s"%(year,month,total_day)
|
||||
return data
|
||||
|
||||
ReportStaffFee.register()
|
||||
ReportStaffFeeDetail.register()
|
||||
|
|
|
@ -32,10 +32,12 @@
|
|||
<tr>
|
||||
<td>{{date}}</td>
|
||||
{{#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>
|
||||
{{/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">{{qty}}</td>
|
||||
<td style="text-align:right">{{currency amount}}</td>
|
||||
|
|
Loading…
Reference in New Issue