81 lines
3.1 KiB
Python
81 lines
3.1 KiB
Python
|
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
|
||
|
|
||
|
def _get_age(self,ids,context):
|
||
|
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
|
||
|
|
||
|
_fields={
|
||
|
"number": fields.Char("Ref.",required=True,search=True),
|
||
|
"name": fields.Char("Name",required=True,search=True),
|
||
|
"identification" : fields.Char("Identification"),
|
||
|
"expiry_card" : fields.Date("Card Expiry"),
|
||
|
"birthday": fields.Date("Birthday",search=True),
|
||
|
"age": fields.Integer("Age", function="_get_age"),
|
||
|
"state": fields.Selection([["temporary","Temporary"],["permanent","Permanent"]],"Status"),
|
||
|
"type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["other","Other"]],"Type"),
|
||
|
"mobile": fields.Char("Mobile",required=False,search=True),
|
||
|
"phone": fields.Char("Phone",search=True),
|
||
|
'email': fields.Char("Email"),
|
||
|
"prof_license" : fields.Char("License."),
|
||
|
"prof_license_date" : fields.Date("License Date"),
|
||
|
"birthday": fields.Date("BirthDay",search=True),
|
||
|
"department_id": fields.Many2One("clinic.department", "Department",search=True),
|
||
|
"patients": fields.Many2Many("clinic.patient","Patients"),
|
||
|
"addresses": fields.One2Many("address","related_id","Addresses"),
|
||
|
"comments": fields.One2Many("message","related_id","Comments"),
|
||
|
"visits": fields.One2Many("clinic.visit","nurse_id","Visits"),
|
||
|
"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"),
|
||
|
'active': fields.Boolean("Active"),
|
||
|
'date': fields.Date("Register Date"),
|
||
|
}
|
||
|
|
||
|
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",
|
||
|
'type': 'nurse',
|
||
|
"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()
|