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