select department under company
parent
20e44d9173
commit
6a43030468
|
@ -0,0 +1,6 @@
|
|||
<action>
|
||||
<field name="string">Department Profiles</field>
|
||||
<field name="view_cls">multi_view</field>
|
||||
<field name="model">clinic.department.profile</field>
|
||||
<field name="menu">gen_menu</field>
|
||||
</action>
|
|
@ -0,0 +1,4 @@
|
|||
<form model="clinic.department.profile">
|
||||
<field name="name"/>
|
||||
<field name="departments"/>
|
||||
</form>
|
|
@ -0,0 +1,3 @@
|
|||
<list model="clinic.department.profile">
|
||||
<field name="name"/>
|
||||
</list>
|
|
@ -0,0 +1,6 @@
|
|||
<inherit inherit="gen_menu">
|
||||
<item string="Users" position="after">
|
||||
<item string="Department Profiles" action="clinic_department_profile"/>
|
||||
</item>
|
||||
</inherit>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<inherit model="base.user" inherit="user_form">
|
||||
<field name="pin_code" position="after">
|
||||
<field name="department_profile_id"/>
|
||||
</field>
|
||||
</inherit>
|
|
@ -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
|
||||
|
|
|
@ -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()
|
|
@ -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()
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue