2014-10-29 09:10:19 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
from netforce.model import Model, fields, get_model
|
|
|
|
from netforce.access import get_active_company, get_active_user, set_active_user
|
|
|
|
|
|
|
|
class Personal(Model):
|
|
|
|
_name="clinic.personal"
|
|
|
|
_string="Personal"
|
|
|
|
_audit_log=True
|
|
|
|
_multi_company=True
|
|
|
|
|
2014-11-05 05:06:43 +00:00
|
|
|
def _get_age(self,ids,context={}):
|
2014-10-29 09:10:19 +00:00
|
|
|
res={}
|
|
|
|
year_now=int(time.strftime("%Y"))
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
age=0
|
|
|
|
if obj.birthday:
|
|
|
|
year_bd=int(obj.birthday[0:4])
|
|
|
|
age=year_now-year_bd
|
|
|
|
res[obj.id]=age
|
|
|
|
return res
|
2014-11-05 05:06:43 +00:00
|
|
|
|
|
|
|
def _get_level(self,ids,context={}):
|
|
|
|
res={}
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
level_id=None
|
|
|
|
for move in obj.moves:
|
|
|
|
level_id=move.level_id.id
|
|
|
|
res[obj.id]=level_id
|
|
|
|
return res
|
2014-10-29 09:10:19 +00:00
|
|
|
|
2014-11-14 01:58:12 +00:00
|
|
|
def _get_cycle(self,ids,context={}):
|
|
|
|
res={}
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
cycle_id=None
|
|
|
|
for line in obj.cycles:
|
|
|
|
cycle=line.cycle_id
|
|
|
|
cycle_id=cycle.id
|
|
|
|
res[obj.id]=cycle_id
|
|
|
|
return res
|
|
|
|
|
2014-10-29 09:10:19 +00:00
|
|
|
_fields={
|
|
|
|
"number": fields.Char("Ref.",required=True,search=True),
|
|
|
|
"name": fields.Char("Name",required=True,search=True),
|
2014-11-05 05:06:43 +00:00
|
|
|
"name_eng": fields.Char("Eng Name",search=True),
|
|
|
|
"nick_name": fields.Char("Nick Name",search=True),
|
|
|
|
"identification" : fields.Char("Identification Card"),
|
|
|
|
"expiry_card" : fields.Date("Expired Card"),
|
2014-10-29 09:10:19 +00:00
|
|
|
"birthday": fields.Date("Birthday",search=True),
|
|
|
|
"age": fields.Integer("Age", function="_get_age"),
|
2014-11-01 03:48:22 +00:00
|
|
|
"state": fields.Selection([["temporary","Temporary"],["permanent","Permanent"]],"Status",search=True),
|
2014-11-05 05:06:43 +00:00
|
|
|
"type": fields.Selection([['personal','Personal'],["doctor","Doctor"],["nurse","Nurse"]],"Type"),
|
|
|
|
"gender": fields.Selection([["male","Male"],["female","Female"]],"Gender"),
|
|
|
|
"nation_id": fields.Many2One("clinic.nation","Nationality"),
|
2014-10-29 09:10:19 +00:00
|
|
|
"mobile": fields.Char("Mobile",required=False,search=True),
|
|
|
|
"phone": fields.Char("Phone",search=True),
|
|
|
|
'email': fields.Char("Email"),
|
2014-11-05 05:06:43 +00:00
|
|
|
"prof_license" : fields.Char("License No."),
|
2014-10-29 09:10:19 +00:00
|
|
|
"prof_license_date" : fields.Date("License Date"),
|
2014-11-05 05:06:43 +00:00
|
|
|
"prof_license_expiry" : fields.Date("Expired License"),
|
2014-10-29 09:10:19 +00:00
|
|
|
"birthday": fields.Date("BirthDay",search=True),
|
|
|
|
"department_id": fields.Many2One("clinic.department", "Department",search=True),
|
2014-11-02 03:38:17 +00:00
|
|
|
"patients": fields.One2Many("clinic.patient","doctor_id","Patients"),
|
2014-11-01 06:04:30 +00:00
|
|
|
"addresses": fields.One2Many("address","personal_id","Addresses"),
|
2014-10-29 09:10:19 +00:00
|
|
|
"comments": fields.One2Many("message","related_id","Comments"),
|
2014-11-02 03:38:17 +00:00
|
|
|
"nurse_visits": fields.One2Many("clinic.visit","nurse_id","Visits"),
|
|
|
|
"doctor_visits": fields.One2Many("clinic.visit","doctor_id","Visits"),
|
2014-10-29 09:10:19 +00:00
|
|
|
"hd_cases": fields.One2Many("clinic.hd.case","nurse_id","HD Cases"),
|
|
|
|
"company_id": fields.Many2One("company","Company"),
|
|
|
|
"user_id": fields.Many2One("base.user","User"),
|
|
|
|
'picture': fields.File("Picture"),
|
|
|
|
'note': fields.Text("Note"),
|
|
|
|
'categ_id': fields.Many2One("clinic.personal.categ", "Category"),
|
2014-11-05 05:06:43 +00:00
|
|
|
'level_id': fields.Many2One("clinic.personal.level", "Personal Level", function="_get_level"),
|
2014-10-29 09:10:19 +00:00
|
|
|
'active': fields.Boolean("Active"),
|
|
|
|
'date': fields.Date("Register Date"),
|
2014-11-02 03:38:17 +00:00
|
|
|
'base': fields.Float("Base Amount"),
|
2014-11-05 05:06:43 +00:00
|
|
|
'hire_date': fields.Date("Hire Date"),
|
|
|
|
'resign_date': fields.Date("Resign Date"),
|
|
|
|
"documents": fields.One2Many("document","related_id","Documents"),
|
2014-11-14 01:58:12 +00:00
|
|
|
"moves": fields.One2Many("clinic.personal.move","personal_id","Personal Moves"),
|
|
|
|
"cycles": fields.One2Many("clinic.personal.cycle","personal_id","Working Cycles"),
|
|
|
|
'cycle_id': fields.Many2One('clinic.cycle','Recent Cycle',function="_get_cycle"),
|
2014-10-29 09:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def _get_number(self,context={}):
|
|
|
|
while 1:
|
|
|
|
seq_id=get_model("sequence").find_sequence(name="Clinic Personal")
|
|
|
|
if not seq_id:
|
|
|
|
return "/"
|
|
|
|
num=get_model("sequence").get_next_number(seq_id,context=context)
|
|
|
|
if not num:
|
|
|
|
return None
|
|
|
|
user_id=get_active_user()
|
|
|
|
set_active_user(1)
|
|
|
|
res=self.search([["number","=",num]])
|
|
|
|
set_active_user(user_id)
|
|
|
|
if not res:
|
|
|
|
return num
|
|
|
|
get_model("sequence").increment_number(seq_id,context=context)
|
|
|
|
|
|
|
|
_defaults={
|
|
|
|
'active': True,
|
|
|
|
"state": "temporary",
|
2014-11-05 05:06:43 +00:00
|
|
|
'type': 'personal',
|
2014-10-29 09:10:19 +00:00
|
|
|
"personal_type": "temporary",
|
|
|
|
"date": lambda *a: time.strftime("%Y-%m-%d"),
|
|
|
|
"number": _get_number,
|
|
|
|
"company_id": lambda *a: get_active_company(),
|
|
|
|
}
|
|
|
|
_order="date desc,number desc"
|
|
|
|
|
|
|
|
Personal.register()
|