From f6ff573d3af047d7832997b5442818a87f3f22f8 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Sun, 15 Mar 2015 22:42:15 +0700 Subject: [PATCH] multi department --- netforce_clinic/layouts/clinic_staff_form.xml | 12 -------- netforce_clinic/models/patient.py | 24 +++++++++++++--- netforce_clinic/models/report_cycle_item.py | 5 +++- .../models/report_discontinue_patient.py | 11 +++++--- .../models/report_hd_case_summary.py | 5 +++- .../models/report_medical_summary.py | 3 ++ .../models/report_recent_patient.py | 11 +++++--- netforce_clinic/models/select_company.py | 10 ++++++- netforce_clinic/models/staff.py | 28 +++++++++++++++++-- netforce_clinic/models/staff_rotation.py | 3 +- netforce_clinic/models/visit_board.py | 5 +++- 11 files changed, 84 insertions(+), 33 deletions(-) diff --git a/netforce_clinic/layouts/clinic_staff_form.xml b/netforce_clinic/layouts/clinic_staff_form.xml index ed742ac..52a43e7 100644 --- a/netforce_clinic/layouts/clinic_staff_form.xml +++ b/netforce_clinic/layouts/clinic_staff_form.xml @@ -58,18 +58,6 @@ - - - - - - - - - - - - diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index 2996936..b374bbf 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -80,8 +80,11 @@ class Patient(Model): def _get_department_names(self,ids,context={}): res={} + user_id=get_active_user() + set_active_user(1) for obj in self.browse(ids): res[obj.id]=','.join([dpt.name for dpt in obj.departments]) + set_active_user(user_id) return res _fields={ @@ -192,13 +195,19 @@ class Patient(Model): def _get_departments(self,context={}): res=get_model('select.company').get_select() if res: - return [res['department_id']] + if res.get("department_ids"): + return res['department_ids'] + else: + return [res['department_id']] return get_model("clinic.department").search([]) def _get_department(self,context={}): res=get_model('select.company').get_select() if res: - return res['department_id'] + if res.get("department_ids"): + return res['department_ids'][0] + else: + return res['department_id'] def _get_branch(self,context={}): res=get_model('select.company').get_select() @@ -207,9 +216,16 @@ class Patient(Model): def _get_default_location(self,context={}): res=get_model('select.company').get_select() + code='' if res: - dpt=get_model("clinic.department").browse(res['department_id']) - return dpt.code + dpt_ids=[] + if res.get("department_ids"): + dpt_ids=res['department_ids'] + else: + dpt_ids=res['department_id'] + dpts=get_model("clinic.department").browse(dpt_ids) + code=','.join([dpt.code for dpt in dpts]) + return code _defaults={ #"number": _get_number, diff --git a/netforce_clinic/models/report_cycle_item.py b/netforce_clinic/models/report_cycle_item.py index 4934666..734d207 100644 --- a/netforce_clinic/models/report_cycle_item.py +++ b/netforce_clinic/models/report_cycle_item.py @@ -33,7 +33,10 @@ class ReportCycleItem(Model): if not branch_id: branch_id=res['branch_id'] if not department_id: - department_id=res['department_id'] + if res.get("department_ids"): + department_id=res['department_ids'][0] + else: + department_id=res['department_id'] res={ 'date': date, 'date_from': date_from, diff --git a/netforce_clinic/models/report_discontinue_patient.py b/netforce_clinic/models/report_discontinue_patient.py index 80aebe4..310026d 100644 --- a/netforce_clinic/models/report_discontinue_patient.py +++ b/netforce_clinic/models/report_discontinue_patient.py @@ -33,12 +33,15 @@ class ReportDiscontinuePatient(Model): department_id=defaults.get('department_id',None) if department_id: department_id=int(department_id) - select_apt=get_model('select.company').get_select() - if select_apt: + select_dpt=get_model('select.company').get_select() + if select_dpt: if not branch_id: - branch_id=select_apt['branch_id'] + branch_id=select_dpt['branch_id'] if not department_id: - department_id=select_apt['department_id'] + if select_dpt.get('department_ids'): + department_id=select_dpt['department_ids'][0] + else: + department_id=select_dpt['department_id'] res={ 'date': date, 'date_from': date_from, diff --git a/netforce_clinic/models/report_hd_case_summary.py b/netforce_clinic/models/report_hd_case_summary.py index dea5912..c955b28 100644 --- a/netforce_clinic/models/report_hd_case_summary.py +++ b/netforce_clinic/models/report_hd_case_summary.py @@ -38,7 +38,10 @@ class ReportHDCaseSummary(Model): def _get_department(self,context={}): res=get_model('select.company').get_select() if res: - return res['department_id'] + if res.get("department_ids"): + return res['department_ids'][0] + else: + return res['department_id'] _defaults={ 'date': lambda *a: time.strftime("%Y-%m-%d"), diff --git a/netforce_clinic/models/report_medical_summary.py b/netforce_clinic/models/report_medical_summary.py index e289915..545f16d 100644 --- a/netforce_clinic/models/report_medical_summary.py +++ b/netforce_clinic/models/report_medical_summary.py @@ -41,6 +41,9 @@ class ReportMedicalSummary(Model): branch_id=int(branch_id or "0") department_id=defaults.get('department_id',None) if not department_id: + if select_dpt.get('department_ids'): + department_id=select_dpt['department_ids'][0] + else: department_id=select_dpt['department_id'] else: department_id=int(department_id or "0") diff --git a/netforce_clinic/models/report_recent_patient.py b/netforce_clinic/models/report_recent_patient.py index 320355c..8249b5e 100644 --- a/netforce_clinic/models/report_recent_patient.py +++ b/netforce_clinic/models/report_recent_patient.py @@ -32,12 +32,15 @@ class ReportRecentPatient(Model): department_id=defaults.get('department_id',None) if department_id: department_id=int(department_id) - select_apt=get_model('select.company').get_select() - if select_apt: + select_dpt=get_model('select.company').get_select() + if select_dpt: if not branch_id: - branch_id=select_apt['branch_id'] + branch_id=select_dpt['branch_id'] if not department_id: - department_id=select_apt['department_id'] + if select_dpt.get('department_ids'): + department_id=select_dpt['department_ids'][0] + else: + department_id=select_dpt['department_id'] res={ 'date': date, 'date_from': date_from, diff --git a/netforce_clinic/models/select_company.py b/netforce_clinic/models/select_company.py index d311fec..31de54b 100644 --- a/netforce_clinic/models/select_company.py +++ b/netforce_clinic/models/select_company.py @@ -175,7 +175,15 @@ class SelectCompany(Model): user=get_model("base.user").browse(user_id) dpt=user.department_id if not dpt: - return {} + dpts=user.department_profile_id.departments + if dpts: + res={ + 'department_ids': [dpt.id for dpt in dpts], + 'branch_id': dpts[0].branch_id.id, #XXX + } + return res + else: + return {} department_id=dpt.id branch_id=dpt.branch_id.id return { diff --git a/netforce_clinic/models/staff.py b/netforce_clinic/models/staff.py index 363ca58..d021dc9 100644 --- a/netforce_clinic/models/staff.py +++ b/netforce_clinic/models/staff.py @@ -102,8 +102,11 @@ class Staff(Model): def _get_department_names(self,ids,context={}): res={} + user_id=get_active_user() + set_active_user(1) for obj in self.browse(ids): res[obj.id]=','.join([dpt.name for dpt in obj.departments]) + set_active_user(user_id) return res _fields={ @@ -189,14 +192,32 @@ class Staff(Model): def _get_departments(self,context={}): res=get_model('select.company').get_select() if res: - return [res['department_id']] + if res.get("department_ids"): + return res['department_ids'] + else: + return [res['department_id']] return get_model("clinic.department").search([]) def _get_default_location(self,context={}): res=get_model('select.company').get_select() + code='' if res: - dpt=get_model("clinic.department").browse(res['department_id']) - return dpt.code + dpt_ids=[] + if res.get("department_ids"): + dpt_ids=res['department_ids'] + else: + dpt_ids=res['department_id'] + dpts=get_model("clinic.department").browse(dpt_ids) + code=','.join([dpt.code for dpt in dpts]) + return code + + def _get_department(self,context={}): + res=get_model('select.company').get_select() + if res: + if res.get("department_ids"): + return res['department_ids'][0] + else: + return res['department_id'] _defaults={ 'active': True, @@ -207,6 +228,7 @@ class Staff(Model): "company_id": lambda *a: get_active_company(), 'branch_id': _get_branch, 'departments': _get_departments, + 'department_id': _get_department, 'location': _get_default_location, } diff --git a/netforce_clinic/models/staff_rotation.py b/netforce_clinic/models/staff_rotation.py index cc79189..beb6e16 100644 --- a/netforce_clinic/models/staff_rotation.py +++ b/netforce_clinic/models/staff_rotation.py @@ -31,6 +31,7 @@ class StaffRotation(Model): 'company_id': fields.Many2One("company","Company"), 'state': fields.Selection([['draft','Draft'],['approved','Approved']],'State'), 'staff_name': fields.Char("Staff Name", function="_get_all",function_multi=True,store=True), #XXX + 'department_id': fields.Many2One("clinic.department", "Department"), #XXX } _defaults={ @@ -57,14 +58,12 @@ class StaffRotation(Model): def create(self,vals,**kw): id=super().create(vals,**kw) self.function_store([id]) - #XXX get_model("clinic.staff").function_store([vals['staff_id']]) return id def write(self,ids,vals,**kw): super().write(ids,vals,**kw) self.function_store(ids) - #XXX staff_ids=[] for obj in self.browse(ids): staff_ids.append(obj.staff_id.id) diff --git a/netforce_clinic/models/visit_board.py b/netforce_clinic/models/visit_board.py index 1916904..da48725 100644 --- a/netforce_clinic/models/visit_board.py +++ b/netforce_clinic/models/visit_board.py @@ -50,7 +50,10 @@ class VisitBoard(Model): if not branch_id: branch_id=res['branch_id'] if not department_id: - department_id=res['department_id'] + if res.get('department_ids'): + department_id=res['department_ids'][0] + else: + department_id=res['department_id'] res={ 'date': date, 'date_from': date_from,