From 4b51b8be9d3d08f574d7ed925c2dd53dec544a23 Mon Sep 17 00:00:00 2001 From: "watcha.h@almacom.co.th" Date: Thu, 9 Apr 2015 11:16:59 +0700 Subject: [PATCH] labor cost report --- netforce_clinic/models/report_labor_cost.py | 64 +++++++++++++++---- .../models/report_labor_cost_summary.py | 18 ++++-- .../templates/report_labor_cost.hbs | 12 +++- 3 files changed, 75 insertions(+), 19 deletions(-) diff --git a/netforce_clinic/models/report_labor_cost.py b/netforce_clinic/models/report_labor_cost.py index 4c751aa..b190080 100644 --- a/netforce_clinic/models/report_labor_cost.py +++ b/netforce_clinic/models/report_labor_cost.py @@ -32,7 +32,7 @@ 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") + report_type=defaults.get("report_type","cross") print('defaults ', defaults) res={ 'date': time.strftime("%Y-%m-%d"), @@ -150,29 +150,47 @@ class ReportLaborCost(Model): ctdata={} for line in get_model('clinic.labor.cost.line').search_browse(dom,order="department_id.name"): cost_id=line.labor_cost_id - categ_name=line.categ_id.name or "" + categ=line.categ_id + categ_name=categ.name or "unknow" 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 + ddata[dpt_name]={ + 'qty': 0, + 'department_id': department.id, + 'branch_id':department.branch_id.id, + } + ddata[dpt_name]['qty']+=qty elif line.type=='nurse': if categ_name not in ctdata.keys(): - ctdata[categ_name]=0 - ctdata[categ_name]+=line.pay_amount or 0 + ctdata[categ_name]={ + 'amount': 0, + 'categ_id': categ.id, + } + ctdata[categ_name]['amount']+=line.pay_amount or 0 if dpt_name not in ndata.keys(): - ndata[dpt_name]=set() + ndata[dpt_name]={ + 'hdcases': set(), + 'department_id': department.id, + 'branch_id':department.branch_id.id, + } for hdcase in citem.hd_cases: - ndata[dpt_name].update({hdcase.id}) + ndata[dpt_name]['hdcases'].update({hdcase.id}) total_amount=0 - for categ_name,amount in ctdata.items(): + for categ_name,vals in ctdata.items(): + amount=vals['amount'] or 0 + categ_id=vals['categ_id'] total_amount+=amount ctlines.append({ 'name': categ_name, 'amount': amount, + 'branch_id': branch_id, + 'categ_id': categ_id, + 'department_id': department_id, + 'staff_type': 'nurse', }) ctlines.append({ 'name': 'รวม', @@ -185,8 +203,14 @@ class ReportLaborCost(Model): 'total_qty': 'รวมจำนวนครั้ง', 'cost': 'เป็นยอดเงินรวม', 'desc': True, + 'department_id': None, + 'branch_id':None, + 'staff_type': 'doctor', }) - for dt_name,qty in ddata.items(): + for dt_name,vals in ddata.items(): + qty=vals['qty'] or 0 + department_id=vals['department_id'] + branch_id=vals['branch_id'] walkin=0 cost=(walkin+qty)*cost_per_case dlines.append({ @@ -196,6 +220,9 @@ class ReportLaborCost(Model): 'total_qty': walkin+qty, 'cost': cost, 'total': 0, + 'department_id': department_id, + 'branch_id': branch_id, + 'staff_type': 'doctor', }) dlines.append({ 'name': 'รวม', @@ -203,6 +230,9 @@ class ReportLaborCost(Model): 'qty2': 0, 'total_qty':0, 'cost': 0, + 'department_id': None, + 'branch_id':None, + 'staff_type': 'doctor', }) for dline in dlines[1:-1]: dlines[-1]['qty']+=dline['qty'] or 0 @@ -215,21 +245,33 @@ class ReportLaborCost(Model): 'qty': 'จำนวนครั้ง', 'cost': 'เป็นยอดเงินรวม', 'total': 'รวม', + 'department_id': None, + 'branch_id': None, 'desc': True, + 'staff_type': 'nurse', }) - for dt_name, hdcases in ndata.items(): + for dt_name, vals in ndata.items(): + hdcases=vals['hdcases'] + department_id=vals['department_id'] + branch_id=vals['branch_id'] total_hdcase=len(hdcases) nlines.append({ 'name': dt_name, 'qty': total_hdcase, 'cost': total_hdcase*vark, + 'department_id': department_id, + 'branch_id': branch_id, 'total': 0, + 'staff_type': 'nurse', }) nlines.append({ 'name': 'รวม', 'qty': 0, 'cost': 0, 'total': 0, + 'department_id': None, + 'branch_id':None, + 'staff_type': 'nurse', }) for nline in nlines[1:-1]: nlines[-1]['qty']+=nline['qty'] or 0 diff --git a/netforce_clinic/models/report_labor_cost_summary.py b/netforce_clinic/models/report_labor_cost_summary.py index 335c35f..8492151 100644 --- a/netforce_clinic/models/report_labor_cost_summary.py +++ b/netforce_clinic/models/report_labor_cost_summary.py @@ -37,6 +37,9 @@ class ReportLaborCostSummary(Model): date_from=defaults.get("date_from", self._get_date_from()) date_to=defaults.get("date_to", self._get_date_to()) branch_id=defaults.get("branch_id") + categ_id=defaults.get("categ_id") + if categ_id: + categ_id=int(categ_id) if branch_id: branch_id=int(branch_id) department_id=defaults.get("department_id") @@ -46,15 +49,20 @@ class ReportLaborCostSummary(Model): if staff_id: staff_id=int(staff_id) staff_type=defaults.get("staff_type","doctor") + level_id=defaults.get("level_id") + if level_id: + level_id=int(level_id) res={ 'date': date, 'date_from': date_from, 'date_to': date_to, 'staff_type': staff_type, 'staff_id': staff_id and staff_id or None, - 'department_id': department_id, - 'branch_id': branch_id, + 'department_id': department_id or None, + 'branch_id': branch_id or None, 'only_value': True, + 'categ_id': categ_id, + 'level_id': level_id, } return res @@ -67,8 +75,8 @@ class ReportLaborCostSummary(Model): only_value=defaults['only_value'] department_id=defaults['department_id'] branch_id=defaults['branch_id'] - level_id=None - categ_id=None + categ_id=defaults['categ_id'] + level_id=defaults['level_id'] dom=[] if ids: obj=self.browse(ids)[0] @@ -97,7 +105,7 @@ class ReportLaborCostSummary(Model): dom.append(['labor_cost_id.cycle_item_id.department_id','=',department_id]) staffs={} citems={} - print('dom ', dom) + print('>> dom: ', dom) total_hdcase=0 for line in get_model("clinic.labor.cost.line").search_browse(dom): lcost=line.labor_cost_id diff --git a/netforce_clinic/templates/report_labor_cost.hbs b/netforce_clinic/templates/report_labor_cost.hbs index f133bf7..d1c5fde 100644 --- a/netforce_clinic/templates/report_labor_cost.hbs +++ b/netforce_clinic/templates/report_labor_cost.hbs @@ -100,7 +100,9 @@ {{#if desc}} {{cost}} {{else}} - {{currency cost}} + + {{currency cost}} + {{/if}} {{/each}} @@ -131,7 +133,9 @@ {{#if desc}} {{cost}} {{else}} - {{currency cost}} + + {{currency cost}} + {{/if}} {{/each}} @@ -142,7 +146,9 @@ {{#each ctlines }} {{name}} - {{currency amount}} + + {{currency amount}} + {{/each}}