optimize loading speed of sickbed

revise1
SPP 2017-11-23 12:31:37 +07:00
parent c4dc2071a2
commit 57baccb9ef
3 changed files with 25 additions and 23 deletions

View File

@ -3,5 +3,6 @@
<field name="view_cls">multi_view</field> <field name="view_cls">multi_view</field>
<field name="model">clinic.sickbed</field> <field name="model">clinic.sickbed</field>
<field name="menu">clinic_menu</field> <field name="menu">clinic_menu</field>
<field name="limit">25</field>
<field name="tabs">[["All",[]],["Archived",[["active","=",false]]],["Available",[["state","=","available"]]],["Not Available",[["state","=","not_available"]]]]</field> <field name="tabs">[["All",[]],["Archived",[["active","=",false]]],["Available",[["state","=","available"]]],["Not Available",[["state","=","not_available"]]]]</field>
</action> </action>

View File

@ -3,7 +3,6 @@
<field name="name"/> <field name="name"/>
<field name="date"/> <field name="date"/>
<field name="patient_id"/> <field name="patient_id"/>
<!--<field name="image" preview="1"/>-->
<field name="department_id"/> <field name="department_id"/>
<field name="branch_id"/> <field name="branch_id"/>
<field name="note"/> <field name="note"/>

View File

@ -1,3 +1,4 @@
from netforce.database import get_connection
from netforce.model import Model, fields, get_model from netforce.model import Model, fields, get_model
from netforce.access import get_active_company, get_active_user, set_active_user from netforce.access import get_active_company, get_active_user, set_active_user
@ -5,38 +6,35 @@ class SickBed(Model):
_name="clinic.sickbed" _name="clinic.sickbed"
_string="Sickbed" _string="Sickbed"
_key=['name','department_id','branch_id'] _key=['name','department_id','branch_id']
def _get_all(self,ids,context={}): def _get_all(self,ids,context={}):
res={} vals={}
db=get_connection()
for obj in self.browse(ids): for obj in self.browse(ids):
hd_case=None
patient_id=None
#image=None #image=None
date='' patient_id=None
set_active_user(1) #FIXME permission denined because of department of patient date=None
if obj.hd_cases: res=db.query("select id,patient_id,date from clinic_hd_case where sickbed_id=%s order by id desc limit 1"%(obj.id))
#hd_case=sorted(obj.hd_cases, key=lambda a: a.id)[-1] if res:
hd_case=obj.hd_cases[-1] hdcase=res[0]
patient=hd_case.patient_id patient_id=hdcase['patient_id']
patient_id=patient.id date=hdcase['date']
#image=patient.image vals[obj.id]={
date=hd_case.date
res[obj.id]={
'patient_id': patient_id, 'patient_id': patient_id,
#'image': image,
'date': date, 'date': date,
#'image': image,
} }
set_active_user(get_active_user()) set_active_user(get_active_user())
return res return vals
_fields={ _fields={
"name": fields.Char("Name",required=True,search=True), "name": fields.Char("Name",required=True,search=True),
"available": fields.Boolean("Available"), "available": fields.Boolean("Available"),
'hd_cases': fields.One2Many("clinic.hd.case",'sickbed_id','HDCases'), 'hd_cases': fields.One2Many("clinic.hd.case",'sickbed_id','HDCases'),
'company_id': fields.Many2One("company","Company"), 'company_id': fields.Many2One("company","Company"),
'patient_id': fields.Many2One("clinic.patient","Lasted Patient",function="_get_all",function_multi=True,domain=[['state','=','admit']]), '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), #'image': fields.File("Image",function="_get_all",function_multi=True),
'date': fields.Date("Lasted Date",function="_get_all",function_multi=True),
"state": fields.Selection([("available","Available"),("not_available","Not Available")],"Status"), "state": fields.Selection([("available","Available"),("not_available","Not Available")],"Status"),
'sequence': fields.Integer("Sequence"), 'sequence': fields.Integer("Sequence"),
'note': fields.Text("Note"), 'note': fields.Text("Note"),
@ -45,8 +43,6 @@ class SickBed(Model):
'active': fields.Boolean("Active"), 'active': fields.Boolean("Active"),
} }
_order="name desc"
def _get_branch(self,context={}): def _get_branch(self,context={}):
user_id=get_active_user() user_id=get_active_user()
staffs=get_model("clinic.staff").search_browse([['user_id','=',user_id]]) staffs=get_model("clinic.staff").search_browse([['user_id','=',user_id]])
@ -65,7 +61,7 @@ class SickBed(Model):
'branch_id': _get_branch, 'branch_id': _get_branch,
'active': True, 'active': True,
} }
_order="branch_id,department_id,sequence,name" _order="branch_id,department_id,sequence,name"
def copy(self,ids,context={}): def copy(self,ids,context={}):
@ -81,7 +77,7 @@ class SickBed(Model):
}, },
'flash': 'Copy succesfully', 'flash': 'Copy succesfully',
} }
def write(self,ids,vals,**kw): def write(self,ids,vals,**kw):
if 'available' in vals.keys(): if 'available' in vals.keys():
if vals['available']: if vals['available']:
@ -89,5 +85,11 @@ class SickBed(Model):
else: else:
vals['state']='not_available' vals['state']='not_available'
super().write(ids,vals,**kw) super().write(ids,vals,**kw)
self.function_store(ids)
def create(self, vals, context={}):
new_id=super().create(vals,context)
self.function_store([new_id])
return new_id
SickBed.register() SickBed.register()