diff --git a/netforce_clinic/actions/clinic_department_profile.xml b/netforce_clinic/actions/clinic_department_profile.xml new file mode 100644 index 0000000..e05cfcf --- /dev/null +++ b/netforce_clinic/actions/clinic_department_profile.xml @@ -0,0 +1,6 @@ + + Department Profiles + multi_view + clinic.department.profile + gen_menu + diff --git a/netforce_clinic/layouts/clinic_menu_inherit.xml b/netforce_clinic/layouts/clinic_account_menu.xml similarity index 100% rename from netforce_clinic/layouts/clinic_menu_inherit.xml rename to netforce_clinic/layouts/clinic_account_menu.xml diff --git a/netforce_clinic/layouts/clinic_department_profile_form.xml b/netforce_clinic/layouts/clinic_department_profile_form.xml new file mode 100644 index 0000000..09ae017 --- /dev/null +++ b/netforce_clinic/layouts/clinic_department_profile_form.xml @@ -0,0 +1,4 @@ +
+ + + diff --git a/netforce_clinic/layouts/clinic_department_profile_list.xml b/netforce_clinic/layouts/clinic_department_profile_list.xml new file mode 100644 index 0000000..62b9be1 --- /dev/null +++ b/netforce_clinic/layouts/clinic_department_profile_list.xml @@ -0,0 +1,3 @@ + + + diff --git a/netforce_clinic/layouts/clinic_gen_menu.xml b/netforce_clinic/layouts/clinic_gen_menu.xml new file mode 100644 index 0000000..349d30f --- /dev/null +++ b/netforce_clinic/layouts/clinic_gen_menu.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/netforce_clinic/layouts/clinic_user_form.xml b/netforce_clinic/layouts/clinic_user_form.xml new file mode 100644 index 0000000..367bf31 --- /dev/null +++ b/netforce_clinic/layouts/clinic_user_form.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index 29e4606..27dd929 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -9,6 +9,7 @@ from . import fin_setting from . import cause_chronic from . import comorbidity from . import department +from . import department_profile from . import education from . import graduation from . import morbidity @@ -102,4 +103,5 @@ from . import shop from . import shop_line from . import sale_order from . import product +from . import base_user from . import select_company diff --git a/netforce_clinic/models/base_user.py b/netforce_clinic/models/base_user.py new file mode 100644 index 0000000..12c4bd5 --- /dev/null +++ b/netforce_clinic/models/base_user.py @@ -0,0 +1,9 @@ +from netforce.model import Model, fields + +class User(Model): + _inherit="base.user" + _fields={ + 'department_profile_id': fields.Many2One("clinic.department.profile","Department Profile"), + } + +User.register() diff --git a/netforce_clinic/models/department_profile.py b/netforce_clinic/models/department_profile.py new file mode 100644 index 0000000..24ad7a7 --- /dev/null +++ b/netforce_clinic/models/department_profile.py @@ -0,0 +1,12 @@ +from netforce.model import Model, fields + +class DepartmentProfile(Model): + _name="clinic.department.profile" + _string="Department Profile" + + _fields={ + 'name': fields.Char("Name", required=True, search=True), + "departments": fields.Many2Many("clinic.department","Departments"), + } + +DepartmentProfile.register() diff --git a/netforce_clinic/models/select_company.py b/netforce_clinic/models/select_company.py index 8c3f60f..bb52089 100644 --- a/netforce_clinic/models/select_company.py +++ b/netforce_clinic/models/select_company.py @@ -21,8 +21,16 @@ class SelectCompany(Model): def get_departments(self,context={}): user_id=get_active_user() - set_active_user(1) - res=get_model("clinic.department").search_read([],["name"]) + user=get_model('base.user').browse(user_id) + dom=[] + if user.department_profile_id: + set_active_user(1) + dpt_ids=[] + for dpt in user.department_profile_id.departments: + dpt_ids.append(dpt.id) + 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] @@ -30,26 +38,29 @@ class SelectCompany(Model): obj=self.browse(ids)[0] if obj.department: user_id=get_active_user() + user=get_model('base.user').browse(user_id) set_active_user(1) + staff=None 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, - }) + if not staff: + raise Exception("No staff match with user %s"%user.name) + 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