multi department
parent
790e601425
commit
87f6ea7c73
|
@ -35,8 +35,8 @@
|
|||
</group>
|
||||
</tab>
|
||||
<tab string="Working Location">
|
||||
<field name="branch_id" required="1"/>
|
||||
<field name="department_id" domain='[["branch_id","=",branch_id]]' required="1"/>
|
||||
<!--<field name="branch_id" required="1"/>-->
|
||||
<!--<field name="department_id" domain='[["branch_id","=",branch_id]]' required="1"/>-->
|
||||
<field name="departments"/>
|
||||
</tab>
|
||||
<tab string="Professional Information">
|
||||
|
|
|
@ -19,7 +19,7 @@ class SelectCompany(Model):
|
|||
'department': _get_department,
|
||||
}
|
||||
|
||||
def get_departments(self,context={}):
|
||||
def _get_departments(self,context={}):
|
||||
user_id=get_active_user()
|
||||
user=get_model('base.user').browse(user_id)
|
||||
dom=[]
|
||||
|
@ -34,7 +34,7 @@ class SelectCompany(Model):
|
|||
set_active_user(user_id)
|
||||
return [(r["name"],r["name"]) for r in res]
|
||||
|
||||
def select(self,ids,context={}):
|
||||
def _select(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
if obj.department:
|
||||
user_id=get_active_user()
|
||||
|
@ -65,4 +65,39 @@ class SelectCompany(Model):
|
|||
res=super().select(ids,context)
|
||||
return res
|
||||
|
||||
def get_departments(self,context={}):
|
||||
user_id=get_active_user()
|
||||
dpt_ids=[]
|
||||
for st in get_model("clinic.staff").search_browse(['user_id','=',user_id]):
|
||||
for dpt in st.departments:
|
||||
dpt_ids.append(dpt.id)
|
||||
dom=[]
|
||||
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]
|
||||
|
||||
def select(self,ids,context={}):
|
||||
user_id=get_active_user()
|
||||
if user_id==1:
|
||||
return
|
||||
obj=self.browse(ids)[0]
|
||||
if obj.department:
|
||||
user=get_model('base.user').browse(user_id)
|
||||
set_active_user(1)
|
||||
for dpt in get_model("clinic.department").search_browse([["name","=",obj.department]]):
|
||||
pf_id=None
|
||||
for pf in get_model("profile").search_read(['code','=',dpt.code]):
|
||||
pf_id=pf['id']
|
||||
print('selected profile ', pf['name'])
|
||||
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()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from netforce.model import Model, fields, get_model
|
||||
from netforce.utils import get_file_path, get_data_path
|
||||
from netforce.utils import get_data_path
|
||||
from netforce.access import get_active_company, get_active_user, set_active_user
|
||||
from netforce.database import get_connection
|
||||
|
||||
|
@ -136,19 +136,14 @@ class ClinicSetting(Model):
|
|||
if user_id !=1:
|
||||
print("Only admin!!")
|
||||
return
|
||||
|
||||
for pt in get_model("clinic.patient").search_browse([]):
|
||||
pt.partner_id.write({
|
||||
'type': 'person',
|
||||
'first_name': pt.first_name or "",
|
||||
'last_name': pt.last_name or "",
|
||||
})
|
||||
dpt_ids=get_model("clinic.department").search([])
|
||||
for st in get_model("clinic.staff").search_browse([]):
|
||||
st.partner_id.write({
|
||||
'type': 'person',
|
||||
'first_name': st.first_name or "",
|
||||
'last_name': st.last_name or "",
|
||||
if not st.departments:
|
||||
st.write({
|
||||
'departments': [['set',dpt_ids]],
|
||||
})
|
||||
print('set all department for ', st.name)
|
||||
|
||||
print('Done!')
|
||||
return
|
||||
|
||||
|
|
|
@ -179,6 +179,9 @@ class Staff(Model):
|
|||
if b_ids:
|
||||
return b_ids[0]
|
||||
|
||||
def _get_dpts(self,context={}):
|
||||
return get_model("clinic.department").search([])
|
||||
|
||||
_defaults={
|
||||
'active': True,
|
||||
"state": "part_time",
|
||||
|
@ -187,6 +190,7 @@ class Staff(Model):
|
|||
"number": _get_number,
|
||||
"company_id": lambda *a: get_active_company(),
|
||||
'branch_id': _get_branch,
|
||||
'departments': _get_dpts,
|
||||
}
|
||||
|
||||
#_key=["name_check","branch_id"] #not working
|
||||
|
@ -275,6 +279,15 @@ class Staff(Model):
|
|||
'partner_id': vals['partner_id'],
|
||||
'staff_id': new_id,
|
||||
})
|
||||
if not obj.departments:
|
||||
dpt_ids=get_model("clinic.department").search([])
|
||||
for st in get_model("clinic.staff").search_browse([]):
|
||||
if not st.departments:
|
||||
st.write({
|
||||
'departments': [['set',dpt_ids]],
|
||||
})
|
||||
print('set all department for ', st.name)
|
||||
|
||||
return new_id
|
||||
|
||||
def write(self,ids,vals,**kw):
|
||||
|
@ -298,6 +311,14 @@ class Staff(Model):
|
|||
'partner_id': vals['partner_id'],
|
||||
'staff_id': ids[0],
|
||||
})
|
||||
if not obj.departments:
|
||||
dpt_ids=get_model("clinic.department").search([])
|
||||
for st in get_model("clinic.staff").search_browse([]):
|
||||
if not st.departments:
|
||||
st.write({
|
||||
'departments': [['set',dpt_ids]],
|
||||
})
|
||||
print('set all department for ', st.name)
|
||||
|
||||
def name_get(self,ids,context={}):
|
||||
vals=[]
|
||||
|
|
Loading…
Reference in New Issue