76 lines
2.7 KiB
Python
76 lines
2.7 KiB
Python
from netforce.model import Model, fields, get_model
|
|
from netforce.access import get_active_company
|
|
|
|
class Branch(Model):
|
|
_name="clinic.branch"
|
|
_string="Branch"
|
|
_key=['name']
|
|
_fields={
|
|
"name": fields.Char("Name",required=True,search=True),
|
|
"code": fields.Char("Code",required=True,search=True),
|
|
"parent_id": fields.Many2One("clinic.branch","Parent"),
|
|
"company_id": fields.Many2One("company","Company"),
|
|
'departments': fields.One2Many("clinic.department","branch_id","Departments"),
|
|
'active': fields.Boolean("Active"),
|
|
"addresses": fields.One2Many("address","related_id","Addresses"),
|
|
}
|
|
|
|
_defaults={
|
|
"company_id": lambda *a: get_active_company(),
|
|
'active': True,
|
|
}
|
|
|
|
def create_profile(self,ids,context={}):
|
|
for obj in self.browse(ids):
|
|
code=obj.code or ''
|
|
pf_ids=get_model('profile').search(['code','=',code])
|
|
if pf_ids:
|
|
raise Exception("Profile %s is already exist"%(code))
|
|
return
|
|
except_perms=['Clinic Menu Settings','Clinic Staff Tab Accounting']
|
|
other_perms=[]
|
|
for otp in get_model('permission').search_read(['name','ilike','clinic'],['name']):
|
|
name=otp['name']
|
|
if name in except_perms:
|
|
continue
|
|
other_perms.append(otp['id'])
|
|
except_model=['clinic.cycle','clinic.department']
|
|
perms=[]
|
|
for model in get_model('model').search_read([['name','ilike','clinic']],['name']):
|
|
vals={
|
|
'model_id': model['id'],
|
|
'perm_read': True,
|
|
'perm_create': True,
|
|
'perm_write': True,
|
|
'perm_delete': True,
|
|
}
|
|
name=model['name']
|
|
if name in except_model:
|
|
vals['perm_create']=False
|
|
vals['perm_write']=False
|
|
vals['perm_delete']=False
|
|
perms.append(('create', vals))
|
|
get_model('profile').create({
|
|
'perms': perms,
|
|
'code': code,
|
|
'name': code,
|
|
'perms': perms,
|
|
'other_perms': [('set',other_perms)],
|
|
'login_company_id': get_active_company(),
|
|
})
|
|
print("create profile %s"%(code))
|
|
|
|
def share_access(self,ids,context={}):
|
|
obj=self.browse(ids)[0]
|
|
obj.create_profile()
|
|
return {
|
|
'next': {
|
|
'name': 'clinic_branch',
|
|
'active_id': obj.id,
|
|
'mode': 'form',
|
|
},
|
|
'flash': 'Branch %s is shared sucessfully'%obj.code,
|
|
}
|
|
|
|
Branch.register()
|