From 57baccb9ef80d29283d2898a109052441832bb42 Mon Sep 17 00:00:00 2001 From: SPP Date: Thu, 23 Nov 2017 12:31:37 +0700 Subject: [PATCH] optimize loading speed of sickbed --- netforce_clinic/actions/clinic_sickbed.xml | 1 + .../layouts/clinic_sickbed_list.xml | 1 - netforce_clinic/models/sickbed.py | 46 ++++++++++--------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/netforce_clinic/actions/clinic_sickbed.xml b/netforce_clinic/actions/clinic_sickbed.xml index 5a0ae9a..a4b59ce 100644 --- a/netforce_clinic/actions/clinic_sickbed.xml +++ b/netforce_clinic/actions/clinic_sickbed.xml @@ -3,5 +3,6 @@ multi_view clinic.sickbed clinic_menu + 25 [["All",[]],["Archived",[["active","=",false]]],["Available",[["state","=","available"]]],["Not Available",[["state","=","not_available"]]]] diff --git a/netforce_clinic/layouts/clinic_sickbed_list.xml b/netforce_clinic/layouts/clinic_sickbed_list.xml index f13239a..5561695 100644 --- a/netforce_clinic/layouts/clinic_sickbed_list.xml +++ b/netforce_clinic/layouts/clinic_sickbed_list.xml @@ -3,7 +3,6 @@ - diff --git a/netforce_clinic/models/sickbed.py b/netforce_clinic/models/sickbed.py index 604edae..1045498 100644 --- a/netforce_clinic/models/sickbed.py +++ b/netforce_clinic/models/sickbed.py @@ -1,3 +1,4 @@ +from netforce.database import get_connection from netforce.model import Model, fields, get_model from netforce.access import get_active_company, get_active_user, set_active_user @@ -5,38 +6,35 @@ class SickBed(Model): _name="clinic.sickbed" _string="Sickbed" _key=['name','department_id','branch_id'] - + def _get_all(self,ids,context={}): - res={} + vals={} + db=get_connection() for obj in self.browse(ids): - hd_case=None - patient_id=None #image=None - date='' - set_active_user(1) #FIXME permission denined because of department of patient - if obj.hd_cases: - #hd_case=sorted(obj.hd_cases, key=lambda a: a.id)[-1] - hd_case=obj.hd_cases[-1] - patient=hd_case.patient_id - patient_id=patient.id - #image=patient.image - date=hd_case.date - res[obj.id]={ + 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]={ 'patient_id': patient_id, - #'image': image, 'date': date, + #'image': image, } set_active_user(get_active_user()) - return res + return vals _fields={ "name": fields.Char("Name",required=True,search=True), "available": fields.Boolean("Available"), 'hd_cases': fields.One2Many("clinic.hd.case",'sickbed_id','HDCases'), '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), - 'date': fields.Date("Lasted Date",function="_get_all",function_multi=True), "state": fields.Selection([("available","Available"),("not_available","Not Available")],"Status"), 'sequence': fields.Integer("Sequence"), 'note': fields.Text("Note"), @@ -45,8 +43,6 @@ class SickBed(Model): 'active': fields.Boolean("Active"), } - _order="name desc" - def _get_branch(self,context={}): user_id=get_active_user() staffs=get_model("clinic.staff").search_browse([['user_id','=',user_id]]) @@ -65,7 +61,7 @@ class SickBed(Model): 'branch_id': _get_branch, 'active': True, } - + _order="branch_id,department_id,sequence,name" def copy(self,ids,context={}): @@ -81,7 +77,7 @@ class SickBed(Model): }, 'flash': 'Copy succesfully', } - + def write(self,ids,vals,**kw): if 'available' in vals.keys(): if vals['available']: @@ -89,5 +85,11 @@ class SickBed(Model): else: vals['state']='not_available' 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()