from netforce.model import Model, fields from netforce.access import get_active_company class PersonalCateg(Model): _name="clinic.personal.categ" _string="Personal Category" _fields={ "name": fields.Char("Name",required=True,search=True), "code": fields.Char("Code",required=True,search=True), 'formular': fields.Text("Formular"), 'sequence': fields.Integer("Sequence"), "type": fields.Selection([("doctor","Doctor"),("nurse","Nurse")],"Personal Type",required=True), } _defaults={ "company_id": lambda *a: get_active_company(), 'sequence': 0, 'type': 'doctor', 'formular': '', } _order="sequence" def name_get(self,ids,context={}): vals=[] for obj in self.browse(ids): name="%s [%s]"%(obj.name,obj.code or "") vals.append((obj.id,name)) return vals def name_search(self,name,domain=None,context={},**kw): dom=[["name","ilike","%"+name+"%"]] if domain: dom=[dom,domain] ids1=self.search(dom) dom=[["code","ilike","%"+name+"%"]] if domain: dom=[dom,domain] ids2=self.search(dom) ids=list(set(ids1+ids2)) return self.name_get(ids,context=context) PersonalCateg.register()