2015-01-14 13:36:23 +00:00
|
|
|
from netforce.model import Model, fields, get_model
|
2014-10-26 04:28:08 +00:00
|
|
|
from netforce.access import get_active_company
|
2014-10-01 08:48:58 +00:00
|
|
|
|
|
|
|
class Department(Model):
|
|
|
|
_name="clinic.department"
|
|
|
|
_string="Department"
|
2014-11-29 14:56:15 +00:00
|
|
|
_key=['code']
|
2014-10-01 08:48:58 +00:00
|
|
|
|
|
|
|
_fields={
|
|
|
|
"name": fields.Char("Name",required=True,search=True),
|
|
|
|
"code": fields.Char("Code",search=True),
|
|
|
|
"parent_id": fields.Many2One("clinic.department", "Parent"),
|
2015-01-11 06:09:40 +00:00
|
|
|
'company_id': fields.Many2One("company","Company"),
|
2015-01-14 13:36:23 +00:00
|
|
|
'branch_id': fields.Many2One("clinic.branch","Branch"),
|
2015-01-13 08:58:47 +00:00
|
|
|
"pick_out_journal_id": fields.Many2One("stock.journal","Stock Journal",required=True),
|
2015-01-15 00:59:27 +00:00
|
|
|
'patients': fields.One2Many("clinic.patient","department_id","Patients"),
|
2015-01-18 10:31:54 +00:00
|
|
|
'staffs': fields.One2Many("clinic.staff","department_id","Staffs"),
|
2015-01-19 09:00:01 +00:00
|
|
|
'active': fields.Boolean("Active"),
|
2014-10-01 08:48:58 +00:00
|
|
|
}
|
2015-01-14 13:36:23 +00:00
|
|
|
|
|
|
|
def _get_branch(self,context={}):
|
|
|
|
b_ids=get_model('clinic.branch').search([])
|
|
|
|
if b_ids:
|
|
|
|
return b_ids[0]
|
2014-10-01 08:48:58 +00:00
|
|
|
|
2014-10-26 04:28:08 +00:00
|
|
|
_defaults={
|
|
|
|
'company_id': lambda *a: get_active_company(),
|
2015-01-14 13:36:23 +00:00
|
|
|
'branch_id': _get_branch,
|
2015-01-19 09:00:01 +00:00
|
|
|
'active': True,
|
2014-10-26 04:28:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 01:31:12 +00:00
|
|
|
_order="code"
|
2015-03-11 01:44:02 +00:00
|
|
|
|
|
|
|
def share_access(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
model_name='clinic.department'
|
|
|
|
model_id=None
|
|
|
|
for model in get_model("model").search_read([['name',model_name]],['name']):
|
|
|
|
model_id=model['id']
|
|
|
|
if not model_id:
|
|
|
|
model_id=get_model("model").create({'name': model_name,'string': 'Clinic Deparment'}),
|
|
|
|
share_id=None
|
|
|
|
for share in get_model('share.access').search_read([['model_id','=', model_id]],['name']):
|
|
|
|
share_id=share['id']
|
|
|
|
if not share_id:
|
|
|
|
share_id=get_model('share.access').create({
|
|
|
|
'model_id': model_id,
|
|
|
|
'default_accesss': 'custom',
|
|
|
|
'filter_type': 'rw',
|
|
|
|
'select_profile': [],
|
|
|
|
})
|
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'action': 'clinic_department',
|
|
|
|
'active_id': obj.id,
|
|
|
|
'mode': 'form',
|
|
|
|
},
|
|
|
|
'flash': 'Department % s is shared sucessfully'%obj.name,
|
|
|
|
}
|
2015-01-18 10:31:54 +00:00
|
|
|
|
2014-10-01 08:48:58 +00:00
|
|
|
Department.register()
|