report labor cost
parent
5aa69ef411
commit
39fa93e8da
|
@ -2,7 +2,7 @@
|
||||||
<field name="date" span="2" mode="month" onchange="onchange_date"/>
|
<field name="date" span="2" mode="month" onchange="onchange_date"/>
|
||||||
<field name="date_from" span="2"/>
|
<field name="date_from" span="2"/>
|
||||||
<field name="date_to" span="2"/>
|
<field name="date_to" span="2"/>
|
||||||
<field name="branch_id" span="3"/>
|
<field name="branch_id" onchange='onchange_branch' span="3"/>
|
||||||
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="3"/>
|
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="3"/>
|
||||||
<foot replace="1">
|
<foot replace="1">
|
||||||
<button string="Compute" method="compute" icon="repeat" type="default"/>
|
<button string="Compute" method="compute" icon="repeat" type="default"/>
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<p></p>
|
<p></p>
|
||||||
<b>Information: </b>State Accept <b style="color:green">'Finish Treatment', 'Waiting Payment', 'Paid'.</b></div>
|
<b>Information: </b>State Accept <b style="color:green">'Waiting Payment', 'Paid'.</b></div>
|
||||||
</template>
|
</template>
|
||||||
</group>
|
</group>
|
||||||
<group span="6" columns="1">
|
<group span="6" columns="1">
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
<field name="branch_id"/>
|
<field name="branch_id"/>
|
||||||
<field name="department_id"/>
|
<field name="department_id"/>
|
||||||
<field name="nurse_total"/>
|
<field name="nurse_total"/>
|
||||||
|
<field name="pt_total"/>
|
||||||
<field name="user_id"/>
|
<field name="user_id"/>
|
||||||
<field name="date_validate"/>
|
<field name="date_validate"/>
|
||||||
<field name="note"/>
|
<field name="note"/>
|
||||||
|
|
|
@ -3,7 +3,6 @@ from calendar import monthrange
|
||||||
|
|
||||||
from netforce.model import Model,fields,get_model
|
from netforce.model import Model,fields,get_model
|
||||||
|
|
||||||
|
|
||||||
class ComputeLaborCost(Model):
|
class ComputeLaborCost(Model):
|
||||||
_name="clinic.compute.labor.cost"
|
_name="clinic.compute.labor.cost"
|
||||||
_string="Compute Labor Cost"
|
_string="Compute Labor Cost"
|
||||||
|
@ -66,4 +65,9 @@ class ComputeLaborCost(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
|
||||||
|
|
||||||
|
def onchange_branch(self,context={}):
|
||||||
|
data=context['data']
|
||||||
|
data['department_id']=None
|
||||||
|
return data
|
||||||
|
|
||||||
ComputeLaborCost.register()
|
ComputeLaborCost.register()
|
||||||
|
|
|
@ -27,8 +27,10 @@ class CycleItem(Model):
|
||||||
def _get_all(self,ids,context={}):
|
def _get_all(self,ids,context={}):
|
||||||
res={}
|
res={}
|
||||||
for obj in self.browse(ids):
|
for obj in self.browse(ids):
|
||||||
|
pt_total=len([hdcase for hdcase in obj.hd_cases if hdcase.state in ('waiting_payment','paid')])
|
||||||
res[obj.id]={
|
res[obj.id]={
|
||||||
'nurse_total': len(obj.lines),
|
'nurse_total': len(obj.lines),
|
||||||
|
'pt_total': pt_total,
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@ -48,6 +50,7 @@ class CycleItem(Model):
|
||||||
"comments": fields.One2Many("message","related_id","Comments"), "company_id": fields.Many2One("company","Company"),
|
"comments": fields.One2Many("message","related_id","Comments"), "company_id": fields.Many2One("company","Company"),
|
||||||
"state": fields.Selection([("draft","Draft"),('pending','Pending'),("validated","Validated")],"Status",required=True),
|
"state": fields.Selection([("draft","Draft"),('pending','Pending'),("validated","Validated")],"Status",required=True),
|
||||||
'nurse_total': fields.Integer("Nurses",function="_get_all",function_multi=True),
|
'nurse_total': fields.Integer("Nurses",function="_get_all",function_multi=True),
|
||||||
|
'pt_total': fields.Integer("Patients",function="_get_all",function_multi=True),
|
||||||
'note': fields.Text("Note"),
|
'note': fields.Text("Note"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,8 +107,8 @@ class CycleItem(Model):
|
||||||
state=hdcase.state
|
state=hdcase.state
|
||||||
if state=='cancelled':
|
if state=='cancelled':
|
||||||
continue
|
continue
|
||||||
if state not in ('completed','waiting_payment','paid'):
|
if state not in ('waiting_payment','paid'):
|
||||||
raise Exception('Invalidate cycle item %s: HD Case %s is not completed' % (obj.name, hdcase.patient_id.name))
|
raise Exception('Invalidate cycle item %s: Can not validate HD Case %s (State not accept)' % (obj.name, hdcase.patient_id.name))
|
||||||
for obj_id in ids:
|
for obj_id in ids:
|
||||||
lcost_ids=get_model("clinic.labor.cost").search([['cycle_item_id','=',obj_id]])
|
lcost_ids=get_model("clinic.labor.cost").search([['cycle_item_id','=',obj_id]])
|
||||||
labor_cost=get_model("clinic.labor.cost")
|
labor_cost=get_model("clinic.labor.cost")
|
||||||
|
|
|
@ -24,7 +24,7 @@ class LaborCost(Model):
|
||||||
def _get_all(self,ids,context={}):
|
def _get_all(self,ids,context={}):
|
||||||
res={}
|
res={}
|
||||||
for obj in self.browse(ids):
|
for obj in self.browse(ids):
|
||||||
hd_cases=obj.cycle_item_id.hd_cases or []
|
hd_cases=[hdcase for hdcase in obj.cycle_item_id.hd_cases if hdcase.state in ('waiting_payment','paid')] or []
|
||||||
total_case=len(hd_cases)
|
total_case=len(hd_cases)
|
||||||
total_a,total_b=0,0
|
total_a,total_b=0,0
|
||||||
total=0.0
|
total=0.0
|
||||||
|
@ -272,13 +272,12 @@ class LaborCost(Model):
|
||||||
'level_id': level_id,
|
'level_id': level_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
#TODO UPDATE COST : like cycle daily
|
|
||||||
item=obj.cycle_item_id
|
item=obj.cycle_item_id
|
||||||
lines=[]
|
lines=[]
|
||||||
# cost's nurses
|
# cost's nurses
|
||||||
for line in item.lines:
|
for line in item.lines:
|
||||||
nurse=line.nurse_id
|
nurse=line.nurse_id
|
||||||
level=line.level_id
|
level=line.level_id or nurse.level_id
|
||||||
vals=levels.get(level.id)
|
vals=levels.get(level.id)
|
||||||
rate,amt,qty=0.0,0.0,0
|
rate,amt,qty=0.0,0.0,0
|
||||||
level_id=level.id
|
level_id=level.id
|
||||||
|
@ -306,6 +305,8 @@ class LaborCost(Model):
|
||||||
for staff in get_model("clinic.staff").search_browse([['number','=','walkin']]):
|
for staff in get_model("clinic.staff").search_browse([['number','=','walkin']]):
|
||||||
dwalkin=staff
|
dwalkin=staff
|
||||||
for hd_case in item.hd_cases:
|
for hd_case in item.hd_cases:
|
||||||
|
if hd_case.state not in ('waiting_payment','paid'):
|
||||||
|
continue
|
||||||
staffs=hd_case.staffs
|
staffs=hd_case.staffs
|
||||||
for ps in staffs:
|
for ps in staffs:
|
||||||
staff=ps.staff_id or dwalkin
|
staff=ps.staff_id or dwalkin
|
||||||
|
|
|
@ -59,6 +59,7 @@ class ReportLaborCost(Model):
|
||||||
show_detail=obj.show_detail
|
show_detail=obj.show_detail
|
||||||
dom.append(['date','>=',date_from])
|
dom.append(['date','>=',date_from])
|
||||||
dom.append(['date','<=',date_to])
|
dom.append(['date','<=',date_to])
|
||||||
|
dom.append(['cycle_item_id.state','=', 'validated'])
|
||||||
if branch_id:
|
if branch_id:
|
||||||
dom.append(['branch_id','=',branch_id])
|
dom.append(['branch_id','=',branch_id])
|
||||||
if department_id:
|
if department_id:
|
||||||
|
@ -67,6 +68,7 @@ class ReportLaborCost(Model):
|
||||||
hdcases={}
|
hdcases={}
|
||||||
hdcase_obj=get_model("clinic.hd.case")
|
hdcase_obj=get_model("clinic.hd.case")
|
||||||
dstates=dict(hdcase_obj._fields['state'].selection)
|
dstates=dict(hdcase_obj._fields['state'].selection)
|
||||||
|
print('dom ', dom)
|
||||||
for hdcase in hdcase_obj.search_browse(dom):
|
for hdcase in hdcase_obj.search_browse(dom):
|
||||||
dpt=hdcase.department_id
|
dpt=hdcase.department_id
|
||||||
state=hdcase.state or ''
|
state=hdcase.state or ''
|
||||||
|
@ -78,6 +80,8 @@ class ReportLaborCost(Model):
|
||||||
'qty':0,
|
'qty':0,
|
||||||
'state':{},
|
'state':{},
|
||||||
}
|
}
|
||||||
|
#total for each department
|
||||||
|
if state in ('waiting_payment','paid'):
|
||||||
hdcases[dpt.id]['qty']+=1
|
hdcases[dpt.id]['qty']+=1
|
||||||
if not hdcases[dpt.id]['state'].get(state):
|
if not hdcases[dpt.id]['state'].get(state):
|
||||||
hdcases[dpt.id]['state'][state]=0
|
hdcases[dpt.id]['state'][state]=0
|
||||||
|
@ -94,17 +98,21 @@ class ReportLaborCost(Model):
|
||||||
for dpt_id, vals in hdcases.items():
|
for dpt_id, vals in hdcases.items():
|
||||||
sub_lines=[]
|
sub_lines=[]
|
||||||
dom2=[['department_id','=',dpt_id]]
|
dom2=[['department_id','=',dpt_id]]
|
||||||
|
qty=vals['qty'] or 0
|
||||||
for state, sqty in vals['state'].items():
|
for state, sqty in vals['state'].items():
|
||||||
|
ok=False
|
||||||
dom3=[['state','=',state]] # last domain
|
dom3=[['state','=',state]] # last domain
|
||||||
|
if state in ('waiting_payment','paid'):
|
||||||
|
ok=True
|
||||||
|
total_hdcase+=qty
|
||||||
dom4=dom+dom2+dom3
|
dom4=dom+dom2+dom3
|
||||||
state=dstates[state]
|
state=dstates[state]
|
||||||
sub_lines.append({
|
sub_lines.append({
|
||||||
'name': state,
|
'name': state,
|
||||||
'qty': sqty,
|
'qty': sqty,
|
||||||
|
'ok': ok,
|
||||||
'action_options': 'mode=list&search_domain=%s&tab_no=0'%replace_quote('%s'%(dom4)),
|
'action_options': 'mode=list&search_domain=%s&tab_no=0'%replace_quote('%s'%(dom4)),
|
||||||
})
|
})
|
||||||
qty=vals['qty'] or 0
|
|
||||||
total_hdcase+=qty
|
|
||||||
lines.append({
|
lines.append({
|
||||||
'name': vals['name'],
|
'name': vals['name'],
|
||||||
'branch_id': vals['branch_id'],
|
'branch_id': vals['branch_id'],
|
||||||
|
|
|
@ -99,7 +99,6 @@ class ReportLaborCostSummary(Model):
|
||||||
citems={}
|
citems={}
|
||||||
print('dom ', dom)
|
print('dom ', dom)
|
||||||
total_hdcase=0
|
total_hdcase=0
|
||||||
states={}
|
|
||||||
for line in get_model("clinic.labor.cost.line").search_browse(dom):
|
for line in get_model("clinic.labor.cost.line").search_browse(dom):
|
||||||
lcost=line.labor_cost_id
|
lcost=line.labor_cost_id
|
||||||
citem=lcost.cycle_item_id
|
citem=lcost.cycle_item_id
|
||||||
|
@ -113,6 +112,7 @@ class ReportLaborCostSummary(Model):
|
||||||
categ=staff.categ_id
|
categ=staff.categ_id
|
||||||
level_name=''
|
level_name=''
|
||||||
if not staff:
|
if not staff:
|
||||||
|
print('no staff', qty, amt)
|
||||||
continue
|
continue
|
||||||
if level_id and staff.level_id.id !=level_id:
|
if level_id and staff.level_id.id !=level_id:
|
||||||
continue
|
continue
|
||||||
|
@ -145,16 +145,8 @@ class ReportLaborCostSummary(Model):
|
||||||
staffs[staff.name][dpt.name]['qty']+=qty
|
staffs[staff.name][dpt.name]['qty']+=qty
|
||||||
|
|
||||||
if not citems.get(citem.id):
|
if not citems.get(citem.id):
|
||||||
#qty=len([hdcase for hdcase in citem.hd_cases if hdcase.state in ('completed', 'waiting_payment', 'paid')])
|
qty=len([hdcase for hdcase in citem.hd_cases if hdcase.state in ('waiting_payment', 'paid')])
|
||||||
qty=0
|
|
||||||
for hdcase in citem.hd_cases:
|
|
||||||
qty+=1
|
|
||||||
#if hdcase.state not in states.keys():
|
|
||||||
#states[hdcase.state]=0
|
|
||||||
#states[hdcase.state]+=1
|
|
||||||
citems[citem.id]=qty
|
citems[citem.id]=qty
|
||||||
#for state,vals in states.items():
|
|
||||||
#print(state, vals)
|
|
||||||
lines=[]
|
lines=[]
|
||||||
dom=[]
|
dom=[]
|
||||||
if branch_id:
|
if branch_id:
|
||||||
|
@ -227,7 +219,6 @@ class ReportLaborCostSummary(Model):
|
||||||
total_lines.append({'amt': round(total,0)})
|
total_lines.append({'amt': round(total,0)})
|
||||||
company_id=get_active_company()
|
company_id=get_active_company()
|
||||||
comp=get_model("company").browse(company_id)
|
comp=get_model("company").browse(company_id)
|
||||||
|
|
||||||
if staff_type!='doctor':
|
if staff_type!='doctor':
|
||||||
total_hdcase=0
|
total_hdcase=0
|
||||||
for k,hdcase_qty in citems.items():
|
for k,hdcase_qty in citems.items():
|
||||||
|
|
|
@ -21,26 +21,30 @@
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
{{#each sub_lines}}
|
{{#each sub_lines}}
|
||||||
|
{{#if ok}}
|
||||||
|
<tr style="color:green;">
|
||||||
|
{{else}}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align:right">{{name}}</td>
|
{{/if}}
|
||||||
|
<td> {{name}}</td>
|
||||||
<td style="text-align:right">
|
<td style="text-align:right">
|
||||||
{{view "link" string=qty action="clinic_hd_case" action_options=action_options}}
|
{{view "link" string=qty action="clinic_hd_case" action_options=action_options}}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
<tr>
|
<tr>
|
||||||
<th style="text-align:right">
|
<th>
|
||||||
Subtotal
|
Subtotal
|
||||||
</th>
|
</th>
|
||||||
<th style="text-align:right">
|
<th style="text-align:right">
|
||||||
<a href="#name=clinic_report_labor_cost_summary&defaults.date={{../../date}}&defaults.date_from={{../../date_from}}&defaults.date_to={{../../date_to}}&defaults.branch_id={{branch_id}}&defaults.department_id={{department_id}}">{{currency qty}}</a>
|
<a target="_blank" href="#name=clinic_report_labor_cost_summary&defaults.date={{../../date}}&defaults.date_from={{../../date_from}}&defaults.date_to={{../../date_to}}&defaults.branch_id={{branch_id}}&defaults.department_id={{department_id}}">{{currency qty}}</a>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
{{else}}
|
{{else}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{name}}</td>
|
<td>{{name}}</td>
|
||||||
<td style="text-align:right">
|
<td style="text-align:right">
|
||||||
<a href="#name=clinic_report_labor_cost_summary&defaults.date={{../../date}}&defaults.date_from={{../../date_from}}&defaults.date_to={{../../date_to}}&defaults.branch_id={{branch_id}}&defaults.department_id={{department_id}}">{{currency qty}}</a>
|
<a target="_blank" href="#name=clinic_report_labor_cost_summary&defaults.date={{../../date}}&defaults.date_from={{../../date_from}}&defaults.date_to={{../../date_to}}&defaults.branch_id={{branch_id}}&defaults.department_id={{department_id}}">{{currency qty}}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
Loading…
Reference in New Issue