From 20e44d917362f99baf9d0ed37856bf87719a55f7 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Mon, 9 Feb 2015 23:47:59 +0700 Subject: [PATCH] select department under company --- .../layouts/clinic_select_company.xml | 5 ++ netforce_clinic/models/__init__.py | 1 + netforce_clinic/models/select_company.py | 57 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 netforce_clinic/layouts/clinic_select_company.xml create mode 100644 netforce_clinic/models/select_company.py diff --git a/netforce_clinic/layouts/clinic_select_company.xml b/netforce_clinic/layouts/clinic_select_company.xml new file mode 100644 index 0000000..989d858 --- /dev/null +++ b/netforce_clinic/layouts/clinic_select_company.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index 3b65837..29e4606 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -102,3 +102,4 @@ from . import shop from . import shop_line from . import sale_order from . import product +from . import select_company diff --git a/netforce_clinic/models/select_company.py b/netforce_clinic/models/select_company.py new file mode 100644 index 0000000..8c3f60f --- /dev/null +++ b/netforce_clinic/models/select_company.py @@ -0,0 +1,57 @@ +from netforce.model import Model, fields, get_model +from netforce.access import get_active_user, set_active_user + +class SelectCompany(Model): + _inherit="select.company" + _fields={ + "department": fields.Selection([],"Deparment") + } + + def _get_department(self,context={}): + user_id=get_active_user() + dpt_name=None + for staff in get_model("clinic.staff").search_browse([['user_id','=',user_id]]): + dpt=staff.department_id + dpt_name=dpt.name + return dpt_name + + _defaults={ + 'department': _get_department, + } + + def get_departments(self,context={}): + user_id=get_active_user() + set_active_user(1) + res=get_model("clinic.department").search_read([],["name"]) + set_active_user(user_id) + return [(r["name"],r["name"]) for r in res] + + def select(self,ids,context={}): + obj=self.browse(ids)[0] + if obj.department: + user_id=get_active_user() + set_active_user(1) + for dpt in get_model("clinic.department").search_browse([["name","=",obj.department]]): + for staff in get_model("clinic.staff").search_browse([['user_id','=',user_id]]): + staff.write({ + 'department_id': dpt.id, + 'branch_id': dpt.branch_id.id, + }) + if staff: + pf_id=None + if dpt.branch_id.code=='LS': + for pf in get_model("profile").search_browse([['name','=','Nurse Laksi']]): + pf_id=pf.id + elif dpt.branch_id.code=='SS': + for pf in get_model("profile").search_browse([['name','=','Nurse Samsan']]): + pf_id=pf.id + 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()