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

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={}):
user_id=get_active_user()
user=get_model('base.user').browse(user_id)
dom=[]
if user.department_profile_id:
set_active_user(1)
res=get_model("clinic.department").search_read([],["name"])
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,14 +38,17 @@ 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:
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']]):