From b4724e98b817411b19814ba4c68d41c47cde8694 Mon Sep 17 00:00:00 2001 From: "watcha.h@almacom.co.th" Date: Wed, 8 Apr 2015 18:38:00 +0700 Subject: [PATCH] improve report --- .../layouts/clinic_report_labor_cost.xml | 3 +- netforce_clinic/models/report_labor_cost.py | 53 +++++++++++++++++++ .../templates/report_labor_cost.hbs | 32 +++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/netforce_clinic/layouts/clinic_report_labor_cost.xml b/netforce_clinic/layouts/clinic_report_labor_cost.xml index 089ac06..b8555fa 100644 --- a/netforce_clinic/layouts/clinic_report_labor_cost.xml +++ b/netforce_clinic/layouts/clinic_report_labor_cost.xml @@ -4,5 +4,6 @@ - + + diff --git a/netforce_clinic/models/report_labor_cost.py b/netforce_clinic/models/report_labor_cost.py index 34541e3..37d746d 100644 --- a/netforce_clinic/models/report_labor_cost.py +++ b/netforce_clinic/models/report_labor_cost.py @@ -15,6 +15,7 @@ class ReportLaborCost(Model): "date_to": fields.Date("To", required=True), "branch_id": fields.Many2One("clinic.branch","Branch"), "department_id": fields.Many2One("clinic.department","Department"), + 'report_type': fields.Selection([['cross','Cross'],['detail','Detail']],'Type'), 'show_detail': fields.Boolean("Show Detail"), } @@ -31,12 +32,14 @@ class ReportLaborCost(Model): defaults=context.get("defaults",{}) date_from=defaults.get("date_from", self._get_date_from()) date_to=defaults.get("date_to", self._get_date_to()) + report_type=defaults.get("report_type","detail") print('defaults ', defaults) res={ 'date': time.strftime("%Y-%m-%d"), 'date_from': date_from, 'date_to': date_to, 'show_detail': False, + 'report_type': report_type, } return res @@ -49,6 +52,7 @@ class ReportLaborCost(Model): branch_id=defaults.get("branch_id") department_id=defaults.get("department_id") show_detail=defaults['show_detail'] + report_type=defaults['report_type'] dom=[] if ids: obj=self.browse(ids)[0] @@ -57,6 +61,7 @@ class ReportLaborCost(Model): branch_id=obj.branch_id.id department_id=obj.department_id.id show_detail=obj.show_detail + report_type=obj.report_type dom.append(['date','>=',date_from]) dom.append(['date','<=',date_to]) dom.append(['cycle_item_id.state','=', 'validated']) @@ -129,16 +134,64 @@ class ReportLaborCost(Model): for line in lines: qty=line['qty'] or 0 total_hdcase+=qty + dlines=[] + nlines=[] + if report_type=='cross': + dom=[ + ['date','>=',date_from], + ['date','<=',date_to], + ['labor_cost_id.cycle_item_id.state','=','validated'], + ] + ddata={} + ndata={} + for line in get_model('clinic.labor.cost.line').search_browse(dom): + cost_id=line.labor_cost_id + citem=cost_id.cycle_item_id + department=citem.department_id + dpt_name=department.name or '' + qty=line.qty or 0 + if line.type=='doctor': + if dpt_name not in ddata.keys(): + ddata[dpt_name]=0 + ddata[dpt_name]+=qty + elif line.type=='nurse': + if dpt_name not in ndata.keys(): + ndata[dpt_name]=set() + for hdcase in citem.hd_cases: + ndata[dpt_name].update({hdcase.id}) + dlines.append({ + 'name': 'แพทย์', + 'qty': 'จำนวนครั้ง', + }) + for dt_name,qty in ddata.items(): + dlines.append({ + 'name': dt_name, + 'qty': qty, + }) + nlines.append({ + 'name': 'พยาบาล', + 'qty': 'จำนวนครั้ง', + }) + for dt_name, hdcases in ndata.items(): + nlines.append({ + 'name': dt_name, + 'qty': len(hdcases) + }) data={ 'company_name': '%s %s' % (company.name or "", sub_name), 'date': date, 'date_from': date_from, 'date_to': date_to, 'lines': lines, + 'dlines': dlines, + 'nlines': nlines, 'total_hdcase': total_hdcase, 'branch_id': branch_id, 'department_id': department_id, 'show_detail': show_detail, + 'report_type': report_type, + #'ddata': ddata, + #'ndata': ndata, } return data diff --git a/netforce_clinic/templates/report_labor_cost.hbs b/netforce_clinic/templates/report_labor_cost.hbs index 66aff56..8bcb41f 100644 --- a/netforce_clinic/templates/report_labor_cost.hbs +++ b/netforce_clinic/templates/report_labor_cost.hbs @@ -6,6 +6,7 @@ From {{date_from}} To {{date_to}} +{{#ifeq report_type "detail"}} @@ -57,3 +58,34 @@
ชั้น
+ +{{else}} + + + + {{#each dlines }} + + {{/each}} + + + {{#each dlines }} + + {{/each}} + + +
{{name}}
{{qty}}
+ + + + {{#each nlines }} + + {{/each}} + + + {{#each nlines }} + + {{/each}} + + +
{{name}}
{{qty}}
+{{/ifeq}}