From 87f6ea7c7379c0de73fde7adc6f985585328133b Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Thu, 12 Mar 2015 18:04:43 +0700 Subject: [PATCH] multi department --- netforce_clinic/layouts/clinic_staff_form.xml | 6 +-- netforce_clinic/models/select_company.py | 39 ++++++++++++++++++- netforce_clinic/models/setting.py | 21 ++++------ netforce_clinic/models/staff.py | 21 ++++++++++ 4 files changed, 69 insertions(+), 18 deletions(-) diff --git a/netforce_clinic/layouts/clinic_staff_form.xml b/netforce_clinic/layouts/clinic_staff_form.xml index ec929b3..8ea65df 100644 --- a/netforce_clinic/layouts/clinic_staff_form.xml +++ b/netforce_clinic/layouts/clinic_staff_form.xml @@ -35,9 +35,9 @@ - - - + + + diff --git a/netforce_clinic/models/select_company.py b/netforce_clinic/models/select_company.py index bb52089..fc08a4b 100644 --- a/netforce_clinic/models/select_company.py +++ b/netforce_clinic/models/select_company.py @@ -19,7 +19,7 @@ class SelectCompany(Model): 'department': _get_department, } - def get_departments(self,context={}): + def _get_departments(self,context={}): user_id=get_active_user() user=get_model('base.user').browse(user_id) dom=[] @@ -34,7 +34,7 @@ class SelectCompany(Model): set_active_user(user_id) return [(r["name"],r["name"]) for r in res] - def select(self,ids,context={}): + def _select(self,ids,context={}): obj=self.browse(ids)[0] if obj.department: user_id=get_active_user() @@ -65,4 +65,39 @@ class SelectCompany(Model): res=super().select(ids,context) return res + def get_departments(self,context={}): + user_id=get_active_user() + dpt_ids=[] + for st in get_model("clinic.staff").search_browse(['user_id','=',user_id]): + for dpt in st.departments: + dpt_ids.append(dpt.id) + dom=[] + if dpt_ids: + dom.append(['id','in',dpt_ids]) + res=get_model("clinic.department").search_read(dom,["name"]) + set_active_user(user_id) + return [(r["name"],r["name"]) for r in res] + + def select(self,ids,context={}): + user_id=get_active_user() + if user_id==1: + return + obj=self.browse(ids)[0] + if obj.department: + user=get_model('base.user').browse(user_id) + set_active_user(1) + for dpt in get_model("clinic.department").search_browse([["name","=",obj.department]]): + pf_id=None + for pf in get_model("profile").search_read(['code','=',dpt.code]): + pf_id=pf['id'] + print('selected profile ', pf['name']) + if pf_id: + user=get_model("base.user").browse(user_id) + user.write({ + 'profile_id': pf_id, + }) + set_active_user(user_id) + res=super().select(ids,context) + return res + SelectCompany.register() diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py index 62bf298..57cf0c0 100644 --- a/netforce_clinic/models/setting.py +++ b/netforce_clinic/models/setting.py @@ -1,5 +1,5 @@ from netforce.model import Model, fields, get_model -from netforce.utils import get_file_path, get_data_path +from netforce.utils import get_data_path from netforce.access import get_active_company, get_active_user, set_active_user from netforce.database import get_connection @@ -136,19 +136,14 @@ class ClinicSetting(Model): if user_id !=1: print("Only admin!!") return - - for pt in get_model("clinic.patient").search_browse([]): - pt.partner_id.write({ - 'type': 'person', - 'first_name': pt.first_name or "", - 'last_name': pt.last_name or "", - }) + dpt_ids=get_model("clinic.department").search([]) for st in get_model("clinic.staff").search_browse([]): - st.partner_id.write({ - 'type': 'person', - 'first_name': st.first_name or "", - 'last_name': st.last_name or "", - }) + if not st.departments: + st.write({ + 'departments': [['set',dpt_ids]], + }) + print('set all department for ', st.name) + print('Done!') return diff --git a/netforce_clinic/models/staff.py b/netforce_clinic/models/staff.py index fe11fbc..5df2668 100644 --- a/netforce_clinic/models/staff.py +++ b/netforce_clinic/models/staff.py @@ -179,6 +179,9 @@ class Staff(Model): if b_ids: return b_ids[0] + def _get_dpts(self,context={}): + return get_model("clinic.department").search([]) + _defaults={ 'active': True, "state": "part_time", @@ -187,6 +190,7 @@ class Staff(Model): "number": _get_number, "company_id": lambda *a: get_active_company(), 'branch_id': _get_branch, + 'departments': _get_dpts, } #_key=["name_check","branch_id"] #not working @@ -275,6 +279,15 @@ class Staff(Model): 'partner_id': vals['partner_id'], 'staff_id': new_id, }) + if not obj.departments: + dpt_ids=get_model("clinic.department").search([]) + for st in get_model("clinic.staff").search_browse([]): + if not st.departments: + st.write({ + 'departments': [['set',dpt_ids]], + }) + print('set all department for ', st.name) + return new_id def write(self,ids,vals,**kw): @@ -298,6 +311,14 @@ class Staff(Model): 'partner_id': vals['partner_id'], 'staff_id': ids[0], }) + if not obj.departments: + dpt_ids=get_model("clinic.department").search([]) + for st in get_model("clinic.staff").search_browse([]): + if not st.departments: + st.write({ + 'departments': [['set',dpt_ids]], + }) + print('set all department for ', st.name) def name_get(self,ids,context={}): vals=[]