clinic/netforce_clinic/models/hospital.py

34 lines
976 B
Python
Raw Permalink Normal View History

2014-12-03 00:05:18 +00:00
from netforce.model import Model, fields
class Hospital(Model):
_name="clinic.hospital"
_string="Hospital"
_key=['code','name']
_fields={
"code": fields.Char("Code",required=True,search=True),
"name": fields.Char("Name",required=True,search=True),
2014-12-08 11:35:39 +00:00
"addresses": fields.One2Many("address","related_id","Addresses"),
2014-12-03 00:05:18 +00:00
}
def name_get(self,ids,context={}):
vals=[]
for obj in self.browse(ids):
name="[%s] %s"%(obj.code,obj.name)
vals.append((obj.id,name))
return vals
def name_search(self,name,domain=None,context={},**kw):
dom=[["code","ilike","%"+name+"%"]]
if domain:
dom=[dom,domain]
ids1=self.search(dom)
dom=[["name","ilike","%"+name+"%"]]
if domain:
dom=[dom,domain]
ids2=self.search(dom)
ids=list(set(ids1+ids2))
return self.name_get(ids,context=context)
Hospital.register()