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="date" required="1" span="2"/>
<field name="type" onchange="onchange_type" span="2"/> <field name="type" onchange="onchange_type" span="2"/>
<field name="staff_id" domain='[["type","=",type]]' span="2"/> <field name="staff_id" domain='[["type","=",type]]' span="2"/>
<field name="department_id" span="2"/>
</form> </form>

View File

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

View File

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

View File

@ -29,30 +29,43 @@ class ReportLaborCostDetail(Model):
weekday, total_day=monthrange(int(year), int(month)) weekday, total_day=monthrange(int(year), int(month))
return "%s-%s-%s"%(year,month,total_day) return "%s-%s-%s"%(year,month,total_day)
_defaults={ #_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"), #'date': lambda *a: time.strftime("%Y-%m-%d"),
'date_from': _get_date_from, #'date_from': _get_date_from,
'date_to': _get_date_to, #'date_to': _get_date_to,
'type': 'doctor', #'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={}): 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() company_id=get_active_company()
comp=get_model("company").browse(company_id) comp=get_model("company").browse(company_id)
staff_type=None defaults=self.default_get(context=context)
staff_id=None date_from=defaults.get("date_from")
department_id=None date_to=defaults.get("date_to")
defaults=context.get("defaults",{}) staff_type=defaults.get("staff_type")
if defaults: staff_id=defaults.get("staff_id")
print('get from default ', defaults) department_id=defaults.get("department_id")
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")
dom=[] dom=[]
if ids: if ids:
print("get from ids") print("get from ids")
@ -82,9 +95,22 @@ class ReportLaborCostDetail(Model):
continue continue
dpt=citem.department_id dpt=citem.department_id
amt=line.amount or 0 amt=line.amount or 0
qty=len(citem.hd_cases) or 0 # qty of patient 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): if not dates.get(date):
dates[date]={ dates[date]={
'labor_cost_id': lcost.id,
'staff_id': staff.id,
'staff_type': staff.type,
dpt.name: { dpt.name: {
'amt': 0, 'amt': 0,
'qty': 0, 'qty': 0,
@ -92,6 +118,9 @@ class ReportLaborCostDetail(Model):
} }
if not dates[date].get(dpt.name): if not dates[date].get(dpt.name):
dates[date].update({ dates[date].update({
'labor_cost_id': lcost.id,
'staff_id': staff.id,
'staff_type': staff.type,
dpt.name: { dpt.name: {
'amt': 0, 'amt': 0,
'qty': 0, 'qty': 0,
@ -108,6 +137,9 @@ class ReportLaborCostDetail(Model):
lvals={ lvals={
'no': no, 'no': no,
'date': kdate, '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 total_qty, total_amt=0, 0
lvals['sub_lines']=[] lvals['sub_lines']=[]
@ -118,7 +150,7 @@ class ReportLaborCostDetail(Model):
if dpt_vals: if dpt_vals:
amt=dpt_vals.get("amt",0) amt=dpt_vals.get("amt",0)
qty=dpt_vals.get("qty",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_amt+=amt
total_qty+=qty total_qty+=qty
lvals['total_qty']=total_qty # total show as right hand side 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_from': _get_date_from,
'date_to': _get_date_to, 'date_to': _get_date_to,
'only_value': True, 'only_value': True,
'type': 'nurse',
} }
def get_report_data(self,ids,context={}): def get_report_data(self,ids,context={}):
res=get_model("clinic.report.labor.cost.summary").default_get() res=get_model("clinic.report.labor.cost.summary").default_get()
date_from=res['date_from'] date_from=res['date_from']
date_to=res['date_to'] date_to=res['date_to']
company_id=get_active_company()
comp=get_model("company").browse(company_id)
staff_type=None
staff_id=None staff_id=None
only_value=False staff_type=res['type']
only_value=res['only_value']
dom=[] dom=[]
if ids: if ids:
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
@ -106,7 +105,7 @@ class ReportLaborCostSummary(Model):
amt=vals2.get("amt",0) amt=vals2.get("amt",0)
staff_type=vals2.get("type",'') staff_type=vals2.get("type",'')
staff_types.update({staff_type}) staff_types.update({staff_type})
lvals['sub_lines'].append({'amt': amt}) lvals['sub_lines'].append({'amt': amt,'dpt_id': dpt['id']})
total+=amt total+=amt
lvals['total']=total lvals['total']=total
lines.append(lvals) lines.append(lvals)
@ -133,7 +132,8 @@ class ReportLaborCostSummary(Model):
total+=amt total+=amt
total_lines.append({'amt': total}) total_lines.append({'amt': total})
print(date_from, ' ', date_to) company_id=get_active_company()
comp=get_model("company").browse(company_id)
data={ data={
'title': title, 'title': title,
'date_from': date_from, 'date_from': date_from,

View File

@ -3,6 +3,12 @@
<thead> <thead>
<tr> <tr>
<th>#</th> <th>#</th>
{{#ifeq staff_type "doctor"}}
<th>HDCase</th>
{{/ifeq}}
{{#ifeq staff_type "nurse"}}
<th>Cycle Item</th>
{{/ifeq}}
<th>HN</th> <th>HN</th>
<th>Patient</th> <th>Patient</th>
<th>Type</th> <th>Type</th>
@ -14,6 +20,16 @@
{{#each lines }} {{#each lines }}
<tr> <tr>
<td>{{no}}</td> <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>{{hn}}</td>
<td>{{patient_name}}</td> <td>{{patient_name}}</td>
<td>{{patient_type_name}}</td> <td>{{patient_type_name}}</td>

View File

@ -33,13 +33,19 @@
<tr> <tr>
<td>{{no}}</th> <td>{{no}}</th>
<td> <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> </td>
{{#each sub_lines}} {{#each sub_lines}}
<td style="text-align:right;">{{qty}}</td> <td style="text-align:right;">
<td style="text-align:right;">{{currency amt zero=""}}</td> <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}} {{/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> <td style="text-align:right;">{{currency total_amt zero=""}}</th>
</tr> </tr>
{{/each}} {{/each}}

View File

@ -26,12 +26,12 @@
</td> </td>
{{#each sub_lines}} {{#each sub_lines}}
<td style="text-align:right;"> <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}}"> <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>
{{currency amt zero=""}}
</a>
</td> </td>
{{/each}} {{/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> </tr>
{{/each}} {{/each}}
</tbody> </tbody>

View File

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