link report

conv_bal
watcha.h 2015-02-18 08:31:12 +07:00
parent 513c2a3059
commit 018f9a1f95
9 changed files with 125 additions and 53 deletions

View File

@ -2,4 +2,5 @@
<field name="date" required="1" span="2"/>
<field name="type" onchange="onchange_type" span="2"/>
<field name="staff_id" domain='[["type","=",type]]' span="2"/>
<field name="department_id" span="2"/>
</form>

View File

@ -29,6 +29,6 @@ class Department(Model):
'active': True,
}
_order="name"
_order="code"
Department.register()

View File

@ -13,34 +13,41 @@ class ReportLaborCostDaily(Model):
"date": fields.Date("Date"),
"type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
'staff_id': fields.Many2One("clinic.staff","Staff"),
'department_id': fields.Many2One("clinic.department",'Department'),
}
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"),
def default_get(self,field_names=None,context={},**kw):
defaults=context.get("defaults",{})
date=defaults.get("date")
if not date:
date=time.strftime("%Y-%m-%d")
staff_type=defaults.get("staff_type","doctor")
staff_id=int(defaults.get('staff_id', "0"))
department_id=int(defaults.get('department_id', "0"))
res={
'date': date,
'type': staff_type,
'staff_id': staff_id and staff_id or None,
'department_id': department_id and department_id or None,
}
print("res ", res)
return res
def get_report_data(self,ids,context={}):
fmt='%Y-%m-%d'
date=time.strftime(fmt)
company_id=get_active_company()
comp=get_model("company").browse(company_id)
staff_type=None
staff_id=None
defaults=context.get("defaults")
date=defaults.get("date")
staff_id=defaults.get("staff_id")
staff_type=defaults.get("staff_type")
dpt_id=defaults.get("department_id")
dom=[]
if ids:
obj=self.browse(ids)[0]
date=obj.date
staff_id=obj.staff_id.id
staff_type=obj.type
dpt_id=obj.department_id.id
dom.append(['date','>=',date])
dom.append(['date','<=',date])
# prevent to load more
@ -50,6 +57,8 @@ class ReportLaborCostDaily(Model):
dom.append(['staff_id','=',staff_id])
if staff_type:
dom.append(['type','=',staff_type])
if dpt_id:
dom.append(['labor_cost_id.cycle_item_id.department_id','=',dpt_id])
lines=[]
no=1
for line in get_model("clinic.labor.cost.line").search_browse(dom):
@ -66,6 +75,8 @@ class ReportLaborCostDaily(Model):
pt=hdcase.patient_id
if staff.id==doctor.id:
lines.append({
'hd_case_number': hdcase.number or '',
'hd_case_id': hdcase.id or '',
'no': no,
'hn': pt.number,
'patient_id': pt.id,
@ -85,6 +96,8 @@ class ReportLaborCostDaily(Model):
pt=hdcase.patient_id
lines.append({
'no': no,
'cycle_item_name': citem.name or '',
'cycle_item_id': citem.id,
'hn': pt.number,
'patient_id': pt.id,
'patient_type_name': pt_type.name or '',

View File

@ -29,30 +29,43 @@ class ReportLaborCostDetail(Model):
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,
'type': 'doctor',
#_defaults={
#'date': lambda *a: time.strftime("%Y-%m-%d"),
#'date_from': _get_date_from,
#'date_to': _get_date_to,
#'type': 'doctor',
#}
def default_get(self,field_names=None,context={},**kw):
defaults=context.get("defaults",{})
date_from=defaults.get("date_from")
if not date_from:
date_from=self._get_date_from()
date_to=defaults.get("date_to")
if not date_to:
date_to=self._get_date_to()
staff_type=defaults.get("staff_type","doctor")
staff_id=int(defaults.get('staff_id', "0"))
department_id=int(defaults.get('department_id', "0"))
res={
'date': time.strftime("%Y-%m-%d"),
'date_from': date_from,
'date_to': date_to,
'type': staff_type,
'staff_id': staff_id and staff_id or None,
'department_id': department_id and department_id or None,
}
return res
def get_report_data(self,ids,context={}):
fmt='%Y-%m-%d'
date_from=time.strftime(fmt)
date_to=time.strftime(fmt)
company_id=get_active_company()
comp=get_model("company").browse(company_id)
staff_type=None
staff_id=None
department_id=None
defaults=context.get("defaults",{})
if defaults:
print('get from default ', defaults)
defaults=self.default_get(context=context)
date_from=defaults.get("date_from")
date_to=defaults.get("date_to")
department_id=defaults.get("department_id")
staff_type=defaults.get("staff_type")
staff_id=defaults.get("staff_id")
department_id=defaults.get("department_id")
dom=[]
if ids:
print("get from ids")
@ -82,9 +95,22 @@ class ReportLaborCostDetail(Model):
continue
dpt=citem.department_id
amt=line.amount or 0
staff=line.staff_id
qty=0
if staff.type=='doctor':
for hdcase in citem.hd_cases:
doctor_id=hdcase.doctor_id.id
if staff.id==doctor_id:
qty+=1
elif staff.type=='nurse':
qty=len(citem.hd_cases) or 0 # qty of patient
else:
pass
if not dates.get(date):
dates[date]={
'labor_cost_id': lcost.id,
'staff_id': staff.id,
'staff_type': staff.type,
dpt.name: {
'amt': 0,
'qty': 0,
@ -92,6 +118,9 @@ class ReportLaborCostDetail(Model):
}
if not dates[date].get(dpt.name):
dates[date].update({
'labor_cost_id': lcost.id,
'staff_id': staff.id,
'staff_type': staff.type,
dpt.name: {
'amt': 0,
'qty': 0,
@ -108,6 +137,9 @@ class ReportLaborCostDetail(Model):
lvals={
'no': no,
'date': kdate,
'staff_type': vals.get("staff_type"),
'staff_id': vals.get("staff_id"),
'labor_cost_id': vals.get("labor_cost_id")
}
total_qty, total_amt=0, 0
lvals['sub_lines']=[]
@ -118,7 +150,7 @@ class ReportLaborCostDetail(Model):
if dpt_vals:
amt=dpt_vals.get("amt",0)
qty=dpt_vals.get("qty",0)
lvals['sub_lines'].append({'qty': qty, 'amt': amt})
lvals['sub_lines'].append({'qty': qty, 'amt': amt, 'dpt_id': dpt['id']})
total_amt+=amt
total_qty+=qty
lvals['total_qty']=total_qty # total show as right hand side

View File

@ -34,17 +34,16 @@ class ReportLaborCostSummary(Model):
'date_from': _get_date_from,
'date_to': _get_date_to,
'only_value': True,
'type': 'nurse',
}
def get_report_data(self,ids,context={}):
res=get_model("clinic.report.labor.cost.summary").default_get()
date_from=res['date_from']
date_to=res['date_to']
company_id=get_active_company()
comp=get_model("company").browse(company_id)
staff_type=None
staff_id=None
only_value=False
staff_type=res['type']
only_value=res['only_value']
dom=[]
if ids:
obj=self.browse(ids)[0]
@ -106,7 +105,7 @@ class ReportLaborCostSummary(Model):
amt=vals2.get("amt",0)
staff_type=vals2.get("type",'')
staff_types.update({staff_type})
lvals['sub_lines'].append({'amt': amt})
lvals['sub_lines'].append({'amt': amt,'dpt_id': dpt['id']})
total+=amt
lvals['total']=total
lines.append(lvals)
@ -133,7 +132,8 @@ class ReportLaborCostSummary(Model):
total+=amt
total_lines.append({'amt': total})
print(date_from, ' ', date_to)
company_id=get_active_company()
comp=get_model("company").browse(company_id)
data={
'title': title,
'date_from': date_from,

View File

@ -3,6 +3,12 @@
<thead>
<tr>
<th>#</th>
{{#ifeq staff_type "doctor"}}
<th>HDCase</th>
{{/ifeq}}
{{#ifeq staff_type "nurse"}}
<th>Cycle Item</th>
{{/ifeq}}
<th>HN</th>
<th>Patient</th>
<th>Type</th>
@ -14,6 +20,16 @@
{{#each lines }}
<tr>
<td>{{no}}</td>
{{#ifeq ../staff_type "doctor"}}
<td>
{{view "link" string=hd_case_number action="clinic_hd_case" action_options="mode=form" active_id=hd_case_id}}
</td>
{{/ifeq}}
{{#ifeq ../staff_type "nurse"}}
<td>
{{view "link" string=cycle_item_name action="clinic_cycle_item" action_options="mode=form" active_id=cycle_item_id}}
</td>
{{/ifeq}}
<td>{{hn}}</td>
<td>{{patient_name}}</td>
<td>{{patient_type_name}}</td>

View File

@ -33,13 +33,19 @@
<tr>
<td>{{no}}</th>
<td>
{{date}}
<a href="#name=clinic_report_labor_cost_daily&defaults.date={{date}}&defaults.staff_type={{staff_type}}&defaults.staff_id={{staff_id}}">{{date}}</a>
</td>
{{#each sub_lines}}
<td style="text-align:right;">{{qty}}</td>
<td style="text-align:right;">{{currency amt zero=""}}</td>
<td style="text-align:right;">
<a href="#name=clinic_report_labor_cost_daily&defaults.date={{../date}}&defaults.staff_type={{../staff_type}}&defaults.staff_id={{../staff_id}}&defaults.department_id={{dpt_id}}">{{currency qty zero=""}}</a>
</td>
<td style="text-align:right;">
{{currency amt zero=""}}
</td>
{{/each}}
<td style="text-align:right;">{{currency total_qty zero=""}}</th>
<td style="text-align:right;">
<a href="#name=clinic_report_labor_cost_daily&defaults.date={{date}}&defaults.staff_type={{staff_type}}&defaults.staff_id={{staff_id}}">{{currency total_qty zero=""}}</a>
</td>
<td style="text-align:right;">{{currency total_amt zero=""}}</th>
</tr>
{{/each}}

View File

@ -26,12 +26,12 @@
</td>
{{#each sub_lines}}
<td style="text-align:right;">
<a href="#name=clinic_report_labor_cost_detail&defaults.date_from={{../../date_from}}&defaults.date_to={{../../date_to}}&defaults.staff_type={{../staff_type}}&defaults.staff_id={{../staff_id}}">
{{currency amt zero=""}}
</a>
<a href="#name=clinic_report_labor_cost_detail&defaults.date_from={{../../date_from}}&defaults.date_to={{../../date_to}}&defaults.staff_type={{../staff_type}}&defaults.staff_id={{../staff_id}}&defaults.department_id={{dpt_id}}">{{currency amt zero=""}}</a>
</td>
{{/each}}
<td style="text-align:right;">{{currency total zero=""}}</th>
<td style="text-align:right;">
<a href="#name=clinic_report_labor_cost_detail&defaults.date_from={{../date_from}}&defaults.date_to={{../date_to}}&defaults.staff_type={{staff_type}}&defaults.staff_id={{staff_id}}">{{currency total zero=""}}</a>
</td>
</tr>
{{/each}}
</tbody>

View File

@ -3,4 +3,8 @@ todo:
- matching payment ***
- script generate hd case
- report doctor & nurse ***
- summary -> ok
- detail -> ok
- daily -> ok
but not link yet