From 4b767ecab8b4fce231019178f2973813ff73e3d9 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Mon, 23 Feb 2015 11:47:51 +0700 Subject: [PATCH] fix labor cost --- .../layouts/clinic_labor_cost_line_form.xml | 24 ++++++++--- netforce_clinic/migrations/__init__.py | 5 ++- .../migrations/update_labor_cost_line.py | 18 ++++++++ netforce_clinic/models/hd_case.py | 2 +- netforce_clinic/models/labor_cost_line.py | 43 +++++++++++++------ .../models/report_labor_cost_detail.py | 23 ++++++---- .../templates/report_labor_cost_detail.hbs | 4 +- .../templates/report_labor_cost_summary.hbs | 8 ++-- 8 files changed, 93 insertions(+), 34 deletions(-) create mode 100644 netforce_clinic/migrations/update_labor_cost_line.py diff --git a/netforce_clinic/layouts/clinic_labor_cost_line_form.xml b/netforce_clinic/layouts/clinic_labor_cost_line_form.xml index 8475905..f63f7d2 100644 --- a/netforce_clinic/layouts/clinic_labor_cost_line_form.xml +++ b/netforce_clinic/layouts/clinic_labor_cost_line_form.xml @@ -1,7 +1,21 @@
- - - - - + + + + + + + + + + + + + + + + + + + diff --git a/netforce_clinic/migrations/__init__.py b/netforce_clinic/migrations/__init__.py index fb1781d..ff4c99e 100644 --- a/netforce_clinic/migrations/__init__.py +++ b/netforce_clinic/migrations/__init__.py @@ -1,3 +1,4 @@ from . import clinic_setting -from . import import_acc -from . import remove_conv_bal +#from . import import_acc +#from . import remove_conv_bal +from . import update_labor_cost_line diff --git a/netforce_clinic/migrations/update_labor_cost_line.py b/netforce_clinic/migrations/update_labor_cost_line.py new file mode 100644 index 0000000..852a1c7 --- /dev/null +++ b/netforce_clinic/migrations/update_labor_cost_line.py @@ -0,0 +1,18 @@ +from datetime import datetime + +from netforce.model import get_model +from netforce import migration +from netforce.database import get_connection + +class Migration(migration.Migration): + _name="clinic.update.labor.cost.line" + _version="2.11.0" + + def migrate(self): + for lcost_line in get_model("clinic.labor.cost.line").search_browse([]): + lcost_line.write({ + 'note': ' ', + }) + return True + +Migration.register() diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index cd5b7c9..fda3f40 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -78,7 +78,7 @@ class HDCase(Model): for line in obj.lines: prod=line.product_id categ=line.product_categ_id - if categ and prod: + if categ and prod and line.reimbursable=='yes': if categ.code=='EPO': name=prod.name or "" name=name.split("-") #XXX diff --git a/netforce_clinic/models/labor_cost_line.py b/netforce_clinic/models/labor_cost_line.py index 6cdc6ef..86733c5 100644 --- a/netforce_clinic/models/labor_cost_line.py +++ b/netforce_clinic/models/labor_cost_line.py @@ -6,37 +6,54 @@ class LaborCostLine(Model): _string="Labor Cost Item" _name_field="labor_cost_id" + def _get_store(self,ids,context={}): + res={} + for obj in self.browse(ids): + staff_type=obj.staff_id.type + citem=obj.labor_cost_id.cycle_item_id + dpt=citem.department_id + br=dpt.branch_id + res[obj.id]={ + 'type': staff_type, + 'branch_id': br.id, + 'department_id': dpt.id, + } + return res + _fields={ "labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True,on_delete="cascade"), - "type": fields.Selection([('staff','Staff'),("doctor","Doctor"),('nurse','Nurse')],"Type",required=True,search=True), + "type": fields.Selection([('staff','Staff'),("doctor","Doctor"),('nurse','Nurse')],"Staff Type",required=True,search=True,function="_get_store",function_multi=True), 'staff_id': fields.Many2One("clinic.staff", "Staff",search=True), 'level_id': fields.Many2One("clinic.staff.level", "Level",search=True), 'cycle_id': fields.Many2One("clinic.cycle", "Cycle",search=True), - 'qty': fields.Integer("#HDCase"), + 'qty': fields.Integer("Qty"), 'rate': fields.Float("Rate",scale=2), 'amount': fields.Float("Amount",scale=2), 'date': fields.Date("Date",search=True), 'description': fields.Char("Description"), 'company_id': fields.Many2One('company','Company'), 'categ_id': fields.Many2One("clinic.staff.categ", "Category",domain=[['type','=','nurse']],search=True), - } - + 'branch_id': fields.Many2One('clinic.branch','Branch',function="_get_store",function_multi=True,store=True,search=True), + 'department_id': fields.Many2One('clinic.department','Department',function="_get_store",function_multi=True,store=True,search=True), + 'note': fields.Text("Note"), + } _defaults={ "company_id": lambda *a: get_active_company(), } - _order="cycle_id,level_id" def create(self,vals,**kw): - staff_id=vals['staff_id'] - staff=get_model("clinic.staff").browse(staff_id) - if staff.type=='doctor': - vals['type']='doctor' - elif staff.type=='nurse': - vals['type']='nurse' - else: - vals['type']='staff' new_id=super().create(vals,**kw) + self.function_store([new_id]) return new_id + def write(self,ids,vals,**kw): + self.function_store(ids) + super().write(ids,vals,**kw) + + def onchange_vals(self,context={}): + data=context['data'] + data['amount']=(data['rate'] or 0)*(data['qty'] or 0) + return data + LaborCostLine.register() diff --git a/netforce_clinic/models/report_labor_cost_detail.py b/netforce_clinic/models/report_labor_cost_detail.py index 157505a..0681dd6 100644 --- a/netforce_clinic/models/report_labor_cost_detail.py +++ b/netforce_clinic/models/report_labor_cost_detail.py @@ -29,13 +29,6 @@ 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', - #} - def default_get(self,field_names=None,context={},**kw): defaults=context.get("defaults",{}) date_from=defaults.get("date_from") @@ -83,6 +76,9 @@ class ReportLaborCostDetail(Model): dom.append(['type','=',staff_type]) if department_id: dom.append(['labor_cost_id.cycle_item_id.department_id','=',department_id]) + + def replace_quote(dom=""): + return dom.replace("'","\"") #prevent to load more data if not staff_id: return {} @@ -114,6 +110,7 @@ class ReportLaborCostDetail(Model): dpt.name: { 'amt': 0, 'qty': 0, + 'dom': [['staff_id','=',staff.id],['date','>=', date],['date','<=',date], ['department_id','=',dpt.id]], }, } if not dates[date].get(dpt.name): @@ -124,6 +121,7 @@ class ReportLaborCostDetail(Model): dpt.name: { 'amt': 0, 'qty': 0, + 'dom': [['staff_id','=',staff.id],['date','>=', date],['date','<=',date], ['department_id','=',dpt.id]], }}) dates[date][dpt.name]['amt']+=amt dates[date][dpt.name]['qty']+=qty @@ -147,10 +145,19 @@ class ReportLaborCostDetail(Model): amt,qty=0,0 dname=dpt['name'] or '' dpt_vals=vals.get(dname) + url_name=None if dpt_vals: amt=dpt_vals.get("amt",0) qty=dpt_vals.get("qty",0) - lvals['sub_lines'].append({'qty': qty, 'amt': amt, 'dpt_id': dpt['id']}) + dom=dpt_vals.get('dom',[]) + if dom: + url_name='#name=clinic_labor_cost_item&mode=list&search_domain=%s&tab_no=0'%replace_quote('%s'%dom), + lvals['sub_lines'].append({ + 'qty': qty, + 'amt': amt, + 'dpt_id': dpt['id'], + 'url_name': url_name, + }) total_amt+=amt total_qty+=qty lvals['total_qty']=total_qty # total show as right hand side diff --git a/netforce_clinic/templates/report_labor_cost_detail.hbs b/netforce_clinic/templates/report_labor_cost_detail.hbs index af491ca..aba60a7 100644 --- a/netforce_clinic/templates/report_labor_cost_detail.hbs +++ b/netforce_clinic/templates/report_labor_cost_detail.hbs @@ -41,7 +41,9 @@ {{currency qty zero=""}} - {{currency amt zero=""}} + + {{currency amt zero=""}} + {{/each}} diff --git a/netforce_clinic/templates/report_labor_cost_summary.hbs b/netforce_clinic/templates/report_labor_cost_summary.hbs index dd18f17..281c0bb 100644 --- a/netforce_clinic/templates/report_labor_cost_summary.hbs +++ b/netforce_clinic/templates/report_labor_cost_summary.hbs @@ -12,10 +12,10 @@ # - Number - Name - Level - Category + รหัส + ชื่อ-สกุล + ตำแหน่ง + หมวดหมู่ {{#each dpts}} {{name}} {{/each}}