diff --git a/netforce_clinic/layouts/clinic_report_labor_cost_daily.xml b/netforce_clinic/layouts/clinic_report_labor_cost_daily.xml index ac3bb96..b046b3f 100644 --- a/netforce_clinic/layouts/clinic_report_labor_cost_daily.xml +++ b/netforce_clinic/layouts/clinic_report_labor_cost_daily.xml @@ -2,4 +2,5 @@ + diff --git a/netforce_clinic/models/department.py b/netforce_clinic/models/department.py index 7a5a07b..586b9bb 100644 --- a/netforce_clinic/models/department.py +++ b/netforce_clinic/models/department.py @@ -29,6 +29,6 @@ class Department(Model): 'active': True, } - _order="name" + _order="code" Department.register() diff --git a/netforce_clinic/models/report_labor_cost_daily.py b/netforce_clinic/models/report_labor_cost_daily.py index e4e6743..d8d76d6 100644 --- a/netforce_clinic/models/report_labor_cost_daily.py +++ b/netforce_clinic/models/report_labor_cost_daily.py @@ -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 '', diff --git a/netforce_clinic/models/report_labor_cost_detail.py b/netforce_clinic/models/report_labor_cost_detail.py index 8177d9b..1b714f5 100644 --- a/netforce_clinic/models/report_labor_cost_detail.py +++ b/netforce_clinic/models/report_labor_cost_detail.py @@ -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) - 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") + defaults=self.default_get(context=context) + date_from=defaults.get("date_from") + date_to=defaults.get("date_to") + 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 - 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): 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 diff --git a/netforce_clinic/models/report_labor_cost_summary.py b/netforce_clinic/models/report_labor_cost_summary.py index 2309ef0..f3c8ded 100644 --- a/netforce_clinic/models/report_labor_cost_summary.py +++ b/netforce_clinic/models/report_labor_cost_summary.py @@ -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, diff --git a/netforce_clinic/templates/report_labor_cost_daily.hbs b/netforce_clinic/templates/report_labor_cost_daily.hbs index 7f9ff4e..9d95e5c 100644 --- a/netforce_clinic/templates/report_labor_cost_daily.hbs +++ b/netforce_clinic/templates/report_labor_cost_daily.hbs @@ -3,6 +3,12 @@ # + {{#ifeq staff_type "doctor"}} + HDCase + {{/ifeq}} + {{#ifeq staff_type "nurse"}} + Cycle Item + {{/ifeq}} HN Patient Type @@ -14,6 +20,16 @@ {{#each lines }} {{no}} + {{#ifeq ../staff_type "doctor"}} + + {{view "link" string=hd_case_number action="clinic_hd_case" action_options="mode=form" active_id=hd_case_id}} + + {{/ifeq}} + {{#ifeq ../staff_type "nurse"}} + + {{view "link" string=cycle_item_name action="clinic_cycle_item" action_options="mode=form" active_id=cycle_item_id}} + + {{/ifeq}} {{hn}} {{patient_name}} {{patient_type_name}} diff --git a/netforce_clinic/templates/report_labor_cost_detail.hbs b/netforce_clinic/templates/report_labor_cost_detail.hbs index 05875f4..5a5a0da 100644 --- a/netforce_clinic/templates/report_labor_cost_detail.hbs +++ b/netforce_clinic/templates/report_labor_cost_detail.hbs @@ -33,13 +33,19 @@ {{no}} - {{date}} + {{date}} {{#each sub_lines}} - {{qty}} - {{currency amt zero=""}} + + {{currency qty zero=""}} + + + {{currency amt zero=""}} + {{/each}} - {{currency total_qty zero=""}} + + {{currency total_qty zero=""}} + {{currency total_amt zero=""}} {{/each}} diff --git a/netforce_clinic/templates/report_labor_cost_summary.hbs b/netforce_clinic/templates/report_labor_cost_summary.hbs index 91425de..ef2c8ae 100644 --- a/netforce_clinic/templates/report_labor_cost_summary.hbs +++ b/netforce_clinic/templates/report_labor_cost_summary.hbs @@ -26,12 +26,12 @@ {{#each sub_lines}} - - {{currency amt zero=""}} - + {{currency amt zero=""}} {{/each}} - {{currency total zero=""}} + + {{currency total zero=""}} + {{/each}} diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt index 3ea09c5..eb34af1 100644 --- a/netforce_clinic/todo.txt +++ b/netforce_clinic/todo.txt @@ -3,4 +3,8 @@ todo: - matching payment *** - script generate hd case - report doctor & nurse *** + - summary -> ok + - detail -> ok + - daily -> ok + but not link yet