From d3a5cb86e218f86dfb8db4e324b7929d1461b66c Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Fri, 30 Jan 2015 18:15:13 +0700 Subject: [PATCH] labor cost and search patient type --- .../actions/clinic_report_staff.xml | 8 ++++ .../layouts/clinic_account_setting.xml | 11 ++++- .../layouts/clinic_hd_case_search.xml | 1 + .../layouts/clinic_labor_cost_entry_form.xml | 2 + .../layouts/clinic_labor_cost_form.xml | 4 +- .../layouts/clinic_menu_inherit.xml | 1 + .../layouts/clinic_report_staff_form.xml | 18 ++++++++ .../layouts/clinic_report_staff_list.xml | 6 +++ netforce_clinic/models/__init__.py | 3 ++ netforce_clinic/models/hd_case.py | 6 +-- netforce_clinic/models/labor_cost.py | 12 +++++- netforce_clinic/models/labor_cost_entry.py | 36 +++++++++++++++- .../models/labor_cost_entry_line.py | 8 ++++ netforce_clinic/models/report_staff.py | 43 +++++++++++++++++++ netforce_clinic/models/report_staff_line.py | 11 +++++ netforce_clinic/models/setting.py | 25 ++++------- .../models/setting_account_product.py | 21 +++++++++ netforce_clinic/models/visit.py | 1 + netforce_clinic/todo.txt | 2 + 19 files changed, 193 insertions(+), 26 deletions(-) create mode 100644 netforce_clinic/actions/clinic_report_staff.xml create mode 100644 netforce_clinic/layouts/clinic_report_staff_form.xml create mode 100644 netforce_clinic/layouts/clinic_report_staff_list.xml create mode 100644 netforce_clinic/models/report_staff.py create mode 100644 netforce_clinic/models/report_staff_line.py create mode 100644 netforce_clinic/models/setting_account_product.py diff --git a/netforce_clinic/actions/clinic_report_staff.xml b/netforce_clinic/actions/clinic_report_staff.xml new file mode 100644 index 0000000..da3ebcb --- /dev/null +++ b/netforce_clinic/actions/clinic_report_staff.xml @@ -0,0 +1,8 @@ + + Report Staff + multi_view + clinic.report.staff + list,form + account_menu + 25 + diff --git a/netforce_clinic/layouts/clinic_account_setting.xml b/netforce_clinic/layouts/clinic_account_setting.xml index 02b4b80..f2ac11a 100644 --- a/netforce_clinic/layouts/clinic_account_setting.xml +++ b/netforce_clinic/layouts/clinic_account_setting.xml @@ -22,7 +22,16 @@ - + + + + + + + + + + diff --git a/netforce_clinic/layouts/clinic_hd_case_search.xml b/netforce_clinic/layouts/clinic_hd_case_search.xml index 45b9f09..5acd5a9 100644 --- a/netforce_clinic/layouts/clinic_hd_case_search.xml +++ b/netforce_clinic/layouts/clinic_hd_case_search.xml @@ -3,6 +3,7 @@ + diff --git a/netforce_clinic/layouts/clinic_labor_cost_entry_form.xml b/netforce_clinic/layouts/clinic_labor_cost_entry_form.xml index 17cf7f4..9a97b90 100644 --- a/netforce_clinic/layouts/clinic_labor_cost_entry_form.xml +++ b/netforce_clinic/layouts/clinic_labor_cost_entry_form.xml @@ -24,6 +24,7 @@ + @@ -37,6 +38,7 @@ + diff --git a/netforce_clinic/layouts/clinic_labor_cost_form.xml b/netforce_clinic/layouts/clinic_labor_cost_form.xml index 775e155..93ec199 100644 --- a/netforce_clinic/layouts/clinic_labor_cost_form.xml +++ b/netforce_clinic/layouts/clinic_labor_cost_form.xml @@ -47,8 +47,8 @@ - - + + diff --git a/netforce_clinic/layouts/clinic_menu_inherit.xml b/netforce_clinic/layouts/clinic_menu_inherit.xml index 51b561d..2dc50dc 100644 --- a/netforce_clinic/layouts/clinic_menu_inherit.xml +++ b/netforce_clinic/layouts/clinic_menu_inherit.xml @@ -9,6 +9,7 @@
+ diff --git a/netforce_clinic/layouts/clinic_report_staff_form.xml b/netforce_clinic/layouts/clinic_report_staff_form.xml new file mode 100644 index 0000000..98dd688 --- /dev/null +++ b/netforce_clinic/layouts/clinic_report_staff_form.xml @@ -0,0 +1,18 @@ +
+ + + + + + + + + + + + + +
diff --git a/netforce_clinic/layouts/clinic_report_staff_list.xml b/netforce_clinic/layouts/clinic_report_staff_list.xml new file mode 100644 index 0000000..4b46ab0 --- /dev/null +++ b/netforce_clinic/layouts/clinic_report_staff_list.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index 1f8c54e..6549256 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -1,6 +1,7 @@ from . import utils from . import setting from . import fin_setting +from . import setting_account_product from . import setting_product from . import setting_level from . import setting_policy @@ -62,6 +63,8 @@ from . import report_hd_case_summary from . import report_medical_summary from . import report_recent_patient from . import report_discontinue_patient +from . import report_staff +from . import report_staff_line from . import report_staff_fee from . import report_staff_fee_detail from . import report_staff_fee_sum diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index 1484d32..26e8024 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -78,7 +78,7 @@ class HDCase(Model): "time_stop": fields.DateTime("Finish Time",required=True), "date": fields.Date("Date",required=True,search=True), "patient_id": fields.Many2One("clinic.patient","Patient",required=True,search=True), - "patient_type_id": fields.Many2One("clinic.patient.type", "Type",function="_get_patient_type"), + "patient_type_id": fields.Many2One("clinic.patient.type", "Type"), "nurse_id": fields.Many2One("clinic.staff","Approve By", domain=[['type','=','nurse']]), "department_id": fields.Many2One("clinic.department", "Department",search=True), "wt_start": fields.Float("Start Wt (kg.)"), @@ -983,8 +983,8 @@ class HDCase(Model): vals['lines']=[] for st_prod in st.products: if patient.type_id.id==st_prod.patient_type_id.id: - price=st_prod.price - qty=st_prod.qty + price=st_prod.price or 0 + qty=st_prod.qty or 0 amt=st_prod.amount categ=st_prod.product_categ_id account_id=st_prod.ar_credit_id.id diff --git a/netforce_clinic/models/labor_cost.py b/netforce_clinic/models/labor_cost.py index 235e734..6ba440a 100644 --- a/netforce_clinic/models/labor_cost.py +++ b/netforce_clinic/models/labor_cost.py @@ -394,12 +394,20 @@ class LaborCost(Model): def update_amt(self,context): total=0.0 data=context['data'] - for line in data['lines']: + for line in data['doctor_lines']: qty=line['qty'] or 0 rate=line['rate'] or 0.0 amt=qty*rate total+=amt - data['total_cost']=total + data['total_dcost']=total + for line in data['nurse_lines']: + #qty=line['qty'] or 0 + #rate=line['rate'] or 0.0 + #amt=qty*rate + amt=line['amount'] or 0.0 + total+=amt + data['total_ncost']=total + data['total']=total return data def create(self,vals,**kw): diff --git a/netforce_clinic/models/labor_cost_entry.py b/netforce_clinic/models/labor_cost_entry.py index fd88875..557ad0f 100644 --- a/netforce_clinic/models/labor_cost_entry.py +++ b/netforce_clinic/models/labor_cost_entry.py @@ -101,18 +101,28 @@ class LaborCostEntry(Model): amt=line.amount state=line.state or staff.state dpt=staff.department_id + citem=line.labor_cost_id.cycle_item_id if not dpt: - dpt=line.labor_cost_id.cycle_item_id.department_id + dpt=citem.department_id if not staffs.get(staff.id): staffs[staff.id]={ + 'staff_type': staff.type, 'department_id': dpt.id, 'qty': 0, 'amt': 0, 'rate': 0, # XXX for special nurse 'state': state, + 'report_staff_id': get_model("clinic.report.staff").create({ + 'date_from': obj.date_from, + 'date_to': obj.date_to, + 'staff_id': staff.id, + }), + 'items': set(), } + # create staff report staffs[staff.id]['qty']+=qty staffs[staff.id]['amt']+=amt + staffs[staff.id]['items'].update({citem.id}) lines=[] timenow=time.strftime("%Y-%m-%d") @@ -120,6 +130,29 @@ class LaborCostEntry(Model): qty=vals['qty'] or 0 amt=vals['amt'] or 0.0 state=vals['state'] + report_staff_id=vals['report_staff_id'] + report_staff=get_model("clinic.report.staff").browse(report_staff_id) + # find hd case for each staff + hids=set() + for item in get_model("clinic.cycle.item").browse(vals['items']): + if vals['staff_type']=='nurse': + for hd_case in item.hd_cases: + hids.update({hd_case.id}) + else: + for hd_case in item.hd_cases: + doctor_id=hd_case.doctor_id.id + if staff_id==doctor_id: + hids.update({hd_case.id}) + rlines=[] + for hid in list(hids): + rlines.append(('create',{ + 'hd_case_id': hid, + })) + report_staff.write({ + 'lines': rlines, + }) + ##### + rate=0.0 if qty: rate=amt/qty # average @@ -131,6 +164,7 @@ class LaborCostEntry(Model): 'rate': rate, 'state': state, 'department_id': vals['department_id'], + 'report_staff_id': report_staff.id, })) for line in obj.lines: diff --git a/netforce_clinic/models/labor_cost_entry_line.py b/netforce_clinic/models/labor_cost_entry_line.py index e42a400..ecd3813 100644 --- a/netforce_clinic/models/labor_cost_entry_line.py +++ b/netforce_clinic/models/labor_cost_entry_line.py @@ -19,6 +19,7 @@ class LaborCostEntryLine(Model): 'department_id': fields.Many2One("clinic.department","Department"), "type": fields.Selection([['staff','Staff'],["doctor","Doctor"],["nurse","Nurse"]],"Type"), "state": fields.Selection([["part_time","Part Time"],["full_time","Full Time"]],"Working Status",search=True), + 'report_staff_id': fields.Many2One("clinic.report.staff","#"), } _order="type" @@ -33,5 +34,12 @@ class LaborCostEntryLine(Model): vals['type']=staff.type new_id=super().create(vals,**kw) return new_id + + def delete(self,ids): + for obj in self.browse(ids): + report=obj.report_staff_id + if report: + report.delete() + super().delete(ids) LaborCostEntryLine.register() diff --git a/netforce_clinic/models/report_staff.py b/netforce_clinic/models/report_staff.py new file mode 100644 index 0000000..f08f7fa --- /dev/null +++ b/netforce_clinic/models/report_staff.py @@ -0,0 +1,43 @@ +from netforce.model import Model, fields + +class ReportStaff(Model): + _name='clinic.report.staff' + _string="Report Staff" + + def _get_store(self,ids,context={}): + res={} + for obj in self.browse(ids): + total=len(obj.lines) + res[obj.id]={ + 'name': total, + } + return res + + def _get_all(self,ids,context={}): + res={} + for obj in self.browse(ids): + total=len(obj.lines) + res[obj.id]={ + 'hdcase_total': total, + } + return res + + _fields={ + 'staff_id': fields.Many2One("clinic.staff",'Staff'), + 'name': fields.Char("Name", function="_get_store",function_multi=True,store=True), + 'date_from': fields.Date("From"), + 'date_to': fields.Date("To"), + 'hdcase_total': fields.Char("Total", function="_get_all",function_multi=True), + 'lines': fields.One2Many("clinic.report.staff.line","report_staff_id","Lines"), + } + + def create(self,vals,**kw): + id=super().create(vals,**kw) + self.function_store([id]) + return id + + def write(self,ids,vals,**kw): + super().write(ids,vals,**kw) + self.function_store(ids) + +ReportStaff.register() diff --git a/netforce_clinic/models/report_staff_line.py b/netforce_clinic/models/report_staff_line.py new file mode 100644 index 0000000..7542256 --- /dev/null +++ b/netforce_clinic/models/report_staff_line.py @@ -0,0 +1,11 @@ +from netforce.model import Model, fields + +class ReportStaffLine(Model): + _name='clinic.report.staff.line' + _string="Report Staff Line" + _fields={ + 'report_staff_id': fields.Many2One("clinic.report.staff","Report Staff", required=True, on_delete="cascade"), + 'hd_case_id': fields.Many2One("clinic.hd.case","HD Case"), + } + +ReportStaffLine.register() diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py index 027ebfb..e7e2950 100644 --- a/netforce_clinic/models/setting.py +++ b/netforce_clinic/models/setting.py @@ -12,6 +12,7 @@ class ClinicSetting(Model): 'file': fields.File("File"), 'levels': fields.One2Many("clinic.setting.level","setting_id","Levels"), 'products': fields.One2Many("clinic.setting.product","setting_id","Products"), + 'account_products': fields.One2Many("clinic.setting.account.product","setting_id","Account Products"), 'invoice_policies': fields.One2Many("clinic.setting.policy","setting_id","Invoice Policies"), 'cost_per_case': fields.Float("Cost Per Case"), 'company_id': fields.Many2One("company", 'Company'), @@ -101,23 +102,13 @@ class ClinicSetting(Model): return True def run_script(self,ids,context={}): - for hdcase in get_model("clinic.hd.case").search_browse([]): - mt=hdcase.membrane_type - for dlz in hdcase.dialyzers: - dlz2=dlz.dialyzer_id - dlz2.write({ - 'membrane_type': mt, - }) - for pt in get_model("clinic.patient").search_browse([]): - count=0 - for hdcase in pt.hd_cases: - if count > 1: - break - if hdcase.vascular_acc: - pt.write({ - 'vascular_acc': hdcase.vascular_acc.id, - }) - count+=1 + count=1 + for hd_case in get_model("clinic.hd.case").search_browse([]): + hd_case.write({ + 'patient_type_id': hd_case.patient_id.type_id.id, + }) + print(count, " update ", hd_case.patient_id.type_id.id) + count+=1 print("Done! ") def reset_last_import(self,ids,context={}): diff --git a/netforce_clinic/models/setting_account_product.py b/netforce_clinic/models/setting_account_product.py new file mode 100644 index 0000000..b5692cf --- /dev/null +++ b/netforce_clinic/models/setting_account_product.py @@ -0,0 +1,21 @@ +from netforce.model import Model, fields +from netforce.access import get_active_company + +class SettingAccountProduct(Model): + _name="clinic.setting.account.product" + _string="Setting Account Product" + _multi_company=True + + _fields={ + "setting_id": fields.Many2One("clinic.setting","Setting",required=True,on_delete="cascade"), + "product_id": fields.Many2One("product","Product"), + "ar_credit_id": fields.Many2One("account.account","AR Credit",multi_company=True), + "ar_debit_id": fields.Many2One("account.account","AR Debit",multi_company=True), + 'company_id': fields.Many2One("company","Company"), + } + + _defaults={ + "company_id": lambda *a: get_active_company(), + } + +SettingAccountProduct.register() diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py index 4d20a4a..1dd999d 100644 --- a/netforce_clinic/models/visit.py +++ b/netforce_clinic/models/visit.py @@ -161,6 +161,7 @@ class Visit(Model): hd_case_obj=get_model("clinic.hd.case") vals={ 'patient_id': obj.patient_id.id, + 'patient_type_id': obj.patient_id.type_id.id, 'vascular_acc': obj.patient_id.vascular_acc.id, 'nurse_id': obj.nurse_id.id, 'department_id': obj.department_id.id, diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt index eff85b9..65df73a 100644 --- a/netforce_clinic/todo.txt +++ b/netforce_clinic/todo.txt @@ -1,5 +1,7 @@ todo: - accounting + - labor cost + - report *** - invoice line -> account -> credit - debit from hd case setting - if user select product by them self