share location

conv_bal
watcha.h@almacom.co.th 2015-05-31 14:14:32 +07:00
parent c3760db0e0
commit 0c2b6adc27
6 changed files with 139 additions and 7 deletions

View File

@ -0,0 +1,6 @@
<action>
<field name="string">Share Location</field>
<field name="view_cls">form_popup</field>
<field name="model">clinic.share.location</field>
<field name="target">_popup</field>
</action>

View File

@ -2,7 +2,7 @@
<head>
<field name="type_id"/>
<button string="Options" dropdown="1">
<!--<item string="Generate Visit" action="clinic_gen_visit"/>-->
<item string="Share Location" action="clinic_share_location"/>
</button>
</head>
<field name="number"/>
@ -17,6 +17,7 @@
<field name="department_id" required="1"/>
<field name="walkin"/>
<field name="vascular_acc"/>
<field name="location" readonly="1"/>
<field name="active" invisible="1"/>
<tabs>
<tab string="General">
@ -95,6 +96,7 @@
</group>
</tab>
-->
<!--
<tab string="HD Departments">
<field name="departments" nolabel="1"/>
<group span="8" columns="1">
@ -107,6 +109,7 @@
<group span="4" columns="1">
</group>
</tab>
-->
<tab string="Accounting" perm="clinic_patient_account">
<field name="partner_id" domain='[["is_patient","=","true"]]'/>
</tab>

View File

@ -0,0 +1,20 @@
<form model="clinic.share.location">
<group form_layout="stacked">
<!--
<template>
<div class="alert alert-warning" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Note:</span>
Please use commas (",") and locaiton code as separator between location such as: location_code1, location_code2 .
</div>
</template>
-->
<field name="location" span="8"/>
<field name="loc_select" selection="get_location" onchange="onchange_location" span="4"/>
<field name="patient_id" invisible="1" span="2"/>
</group>
<foot>
<button string="Share" type="primary" icon="share-alt" method="do_share"/>
<button string="Clear" type="default" method="do_clear"/>
</foot>
</form>

View File

@ -135,5 +135,6 @@ from . import report_thai_wht_certif
from . import num2word
from . import province
from . import change_visit
from . import share_location
#from . import district
#from . import subdistrict

View File

@ -74,9 +74,6 @@ class Patient(Model):
dpt_codes=set()
# main department
dpt_codes.update({obj.department_id.code})
# hd department
for dpt in obj.departments:
dpt_codes.update({dpt.code})
# cycle settings
for cline in obj.cycles:
dpt_codes.update({cline.department_id.code})
@ -178,9 +175,8 @@ class Patient(Model):
"vascular_acc": fields.Many2One("clinic.vascular.access","Vascular Ac."),
'state': fields.Selection([['admit','Admit'],['dispose','Dispose']],'State'),
'walkin': fields.Selection([['yes','Yes'],['no','No']],"Walkin"),
'departments': fields.Many2Many("clinic.department","Departments"),
'department_names': fields.Text("Departments",function="_get_department_names"),
'location': fields.Char("Location",function="_get_location",store=True), #to filter
'location': fields.Char("Location"), #to filter
}
def _get_number(self,context={}):
@ -275,7 +271,6 @@ class Patient(Model):
}
_sql_constraints=("clinic_patient_key_uniq","unique(name_check)","name should be unique"),
#_order="reg_date desc"
def check_idcard(self,card_type,idcard=''):
res=True

View File

@ -0,0 +1,107 @@
from netforce.access import get_active_user, set_active_user
from netforce.model import Model, fields, get_model
from netforce.database import get_connection
class ShareLocation(Model):
_name="clinic.share.location"
_transient=True
_select_patient=None
_fields={
'patient_id': fields.Many2One("clinic.patient","Patient",required=True),
'location': fields.Char("Location",required=True),
"loc_select": fields.Selection([],"Departments"),
}
def get_location_user(self,patient_id=None,patient_only=False):
user_id=get_active_user()
user=get_model('base.user').browse(user_id)
department=user.department_id
loc=[]
if department and not patient_only:
loc.append(department.code)
if patient_id:
patient=get_model('clinic.patient').browse(patient_id)
self._select_patient=patient.id
department=patient.department_id
loc.append(department.code)
return loc
def default_get(self,field_names=None,context={},**kw):
refer_id=context.get("refer_id")
patient_id=None
location=''
if refer_id:
patient_id=int(refer_id)
patient=get_model('clinic.patient').browse(patient_id)
location=patient.location or ''
uloc=self.get_location_user(patient.id)
new_loc=[]
for loc_code in location.split(","):
if loc_code in uloc:
continue
new_loc.append(loc_code)
location=','.join(new_loc)
res={
'patient_id': patient_id,
'location': location,
}
return res
def get_location(self,context={}):
user_id=get_active_user()
uloc=self.get_location_user(self._select_patient)
set_active_user(1)
res=get_model("clinic.department").search_read([],["code","name"])
set_active_user(user_id)
return [(r["code"],'%s [%s]'%(r['name'],r["code"])) for r in res if r['code'] not in uloc]
def onchange_location(self,context={}):
data=context['data']
location=data['location'] or ''
location=location.split(",")+[data['loc_select'] or '']
sloc=list(set(location))
data['location']=','.join([loc for loc in sloc if loc])
return data
def do_share(self,ids,context={}):
obj=self.browse(ids)[0]
patient=obj.patient_id
uloc=self.get_location_user(patient.id,patient_only=True)
new_loc=uloc
for loc_code in obj.location.split(","):
res=get_model('clinic.department').search([['code','=',loc_code]])
if not res:
raise Exception("Department code %s not found!"%(loc_code))
new_loc.append(loc_code)
main_loc=patient.department_id.code
if main_loc not in new_loc:
raise Exception("Can not delete main department %s"%(main_loc))
#TODO check user location
location=','.join(new_loc)
db=get_connection()
db.execute("update clinic_patient set location=%s where id=%s",location,patient.id)
return {
'next': {
'name': 'clinic_patient',
'mode': 'form',
'active_id': patient.id,
},
}
def do_clear(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({
'location': '',
})
return {
'next': {
'name': 'clinic_share_location',
'mode': 'form',
'active_id': ids[0],
},
}
ShareLocation.register()