clinic/netforce_clinic/models/hospital.py

34 lines
976 B
Python

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),
"addresses": fields.One2Many("address","related_id","Addresses"),
}
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()