select department under company

conv_bal
watcha.h 2015-02-10 08:28:30 +07:00
parent 20e44d9173
commit 6a43030468
10 changed files with 73 additions and 15 deletions

View File

@ -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>

View File

@ -0,0 +1,4 @@
<form model="clinic.department.profile">
<field name="name"/>
<field name="departments"/>
</form>

View File

@ -0,0 +1,3 @@
<list model="clinic.department.profile">
<field name="name"/>
</list>

View File

@ -0,0 +1,6 @@
<inherit inherit="gen_menu">
<item string="Users" position="after">
<item string="Department Profiles" action="clinic_department_profile"/>
</item>
</inherit>

View File

@ -0,0 +1,5 @@
<inherit model="base.user" inherit="user_form">
<field name="pin_code" position="after">
<field name="department_profile_id"/>
</field>
</inherit>

View File

@ -9,6 +9,7 @@ from . import fin_setting
from . import cause_chronic from . import cause_chronic
from . import comorbidity from . import comorbidity
from . import department from . import department
from . import department_profile
from . import education from . import education
from . import graduation from . import graduation
from . import morbidity from . import morbidity
@ -102,4 +103,5 @@ from . import shop
from . import shop_line from . import shop_line
from . import sale_order from . import sale_order
from . import product from . import product
from . import base_user
from . import select_company from . import select_company

View File

@ -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()

View File

@ -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()

View File

@ -21,8 +21,16 @@ class SelectCompany(Model):
def get_departments(self,context={}): def get_departments(self,context={}):
user_id=get_active_user() user_id=get_active_user()
set_active_user(1) user=get_model('base.user').browse(user_id)
res=get_model("clinic.department").search_read([],["name"]) 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) set_active_user(user_id)
return [(r["name"],r["name"]) for r in res] return [(r["name"],r["name"]) for r in res]
@ -30,26 +38,29 @@ class SelectCompany(Model):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
if obj.department: if obj.department:
user_id=get_active_user() user_id=get_active_user()
user=get_model('base.user').browse(user_id)
set_active_user(1) set_active_user(1)
staff=None
for dpt in get_model("clinic.department").search_browse([["name","=",obj.department]]): 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]]): for staff in get_model("clinic.staff").search_browse([['user_id','=',user_id]]):
staff.write({ staff.write({
'department_id': dpt.id, 'department_id': dpt.id,
'branch_id': dpt.branch_id.id, 'branch_id': dpt.branch_id.id,
}) })
if staff: if not staff:
pf_id=None raise Exception("No staff match with user %s"%user.name)
if dpt.branch_id.code=='LS': pf_id=None
for pf in get_model("profile").search_browse([['name','=','Nurse Laksi']]): if dpt.branch_id.code=='LS':
pf_id=pf.id for pf in get_model("profile").search_browse([['name','=','Nurse Laksi']]):
elif dpt.branch_id.code=='SS': pf_id=pf.id
for pf in get_model("profile").search_browse([['name','=','Nurse Samsan']]): elif dpt.branch_id.code=='SS':
pf_id=pf.id for pf in get_model("profile").search_browse([['name','=','Nurse Samsan']]):
if pf_id: pf_id=pf.id
user=get_model("base.user").browse(user_id) if pf_id:
user.write({ user=get_model("base.user").browse(user_id)
'profile_id': pf_id, user.write({
}) 'profile_id': pf_id,
})
set_active_user(user_id) set_active_user(user_id)
res=super().select(ids,context) res=super().select(ids,context)
return res return res