clinic/netforce_clinic/models/sickbed.py

96 lines
3.4 KiB
Python
Raw Permalink Normal View History

2017-11-23 05:31:37 +00:00
from netforce.database import get_connection
2014-12-19 16:57:34 +00:00
from netforce.model import Model, fields, get_model
2015-03-13 07:43:57 +00:00
from netforce.access import get_active_company, get_active_user, set_active_user
2014-12-19 16:57:34 +00:00
class SickBed(Model):
_name="clinic.sickbed"
_string="Sickbed"
2015-01-21 10:57:11 +00:00
_key=['name','department_id','branch_id']
2017-11-23 05:31:37 +00:00
2015-01-09 05:19:52 +00:00
def _get_all(self,ids,context={}):
2017-11-23 05:31:37 +00:00
vals={}
db=get_connection()
2015-01-09 05:19:52 +00:00
for obj in self.browse(ids):
#image=None
2017-11-23 05:31:37 +00:00
patient_id=None
date=None
res=db.query("select id,patient_id,date from clinic_hd_case where sickbed_id=%s order by id desc limit 1"%(obj.id))
if res:
hdcase=res[0]
patient_id=hdcase['patient_id']
date=hdcase['date']
vals[obj.id]={
2015-01-09 05:19:52 +00:00
'patient_id': patient_id,
'date': date,
2017-11-23 05:31:37 +00:00
#'image': image,
2015-01-09 05:19:52 +00:00
}
2015-03-13 07:43:57 +00:00
set_active_user(get_active_user())
2017-11-23 05:31:37 +00:00
return vals
2014-12-19 16:57:34 +00:00
_fields={
"name": fields.Char("Name",required=True,search=True),
"available": fields.Boolean("Available"),
'hd_cases': fields.One2Many("clinic.hd.case",'sickbed_id','HDCases'),
2015-01-09 05:19:52 +00:00
'company_id': fields.Many2One("company","Company"),
2017-11-23 05:31:37 +00:00
'patient_id': fields.Many2One("clinic.patient","Lasted Patient",function="_get_all",function_multi=True, store=True, domain=[['state','=','admit']]),
'date': fields.Date("Lasted Date",function="_get_all",function_multi=True, store=True,),
#'image': fields.File("Image",function="_get_all",function_multi=True),
2015-01-09 05:19:52 +00:00
"state": fields.Selection([("available","Available"),("not_available","Not Available")],"Status"),
2015-01-09 07:48:01 +00:00
'sequence': fields.Integer("Sequence"),
2015-01-09 10:39:33 +00:00
'note': fields.Text("Note"),
2015-01-14 11:00:14 +00:00
'branch_id': fields.Many2One("clinic.branch","Branch",required=True, search=True),
2015-01-16 11:19:49 +00:00
'department_id': fields.Many2One("clinic.department","Department",required=True, search=True),
2015-01-21 11:31:51 +00:00
'active': fields.Boolean("Active"),
2014-12-19 16:57:34 +00:00
}
2015-01-14 13:36:23 +00:00
def _get_branch(self,context={}):
2015-01-14 11:00:14 +00:00
user_id=get_active_user()
staffs=get_model("clinic.staff").search_browse([['user_id','=',user_id]])
branch_id=None
if staffs:
staff=staffs[0]
if staff.branch_id:
branch_id=staff.branch_id.id
return branch_id
2014-12-19 16:57:34 +00:00
_defaults={
'available': True,
2015-01-09 05:19:52 +00:00
"company_id": lambda *a: get_active_company(),
2015-01-09 07:48:01 +00:00
'sequence': 0,
2015-01-13 06:08:55 +00:00
'state': 'available',
2015-01-14 13:36:23 +00:00
'branch_id': _get_branch,
2015-01-21 11:31:51 +00:00
'active': True,
2014-12-19 16:57:34 +00:00
}
2017-11-23 05:31:37 +00:00
2015-01-21 10:57:11 +00:00
_order="branch_id,department_id,sequence,name"
2014-12-19 16:57:34 +00:00
def copy(self,ids,context={}):
obj=self.browse(ids)[0]
new_id=get_model("clinic.sickbed").create({
'name': '%s(copy)' % obj.name,
})
return {
'next': {
'name': 'clinic_sickbed',
'mode': 'form',
'active_id': new_id,
},
'flash': 'Copy succesfully',
}
2017-11-23 05:31:37 +00:00
2015-01-14 03:55:08 +00:00
def write(self,ids,vals,**kw):
if 'available' in vals.keys():
if vals['available']:
vals['state']='available'
else:
vals['state']='not_available'
super().write(ids,vals,**kw)
2017-11-23 05:31:37 +00:00
self.function_store(ids)
def create(self, vals, context={}):
new_id=super().create(vals,context)
self.function_store([new_id])
return new_id
2014-12-19 16:57:34 +00:00
SickBed.register()