Skip to Content
Menu
This question has been flagged
5 Replies
3544 Views

```

@api.multi 

def name_get(self): 

result = [] 

for record in self: 

name = record.name + ' - ' + str(record.id_proof_no) 

result.append((record.id, name)) 

return result

```

working fine 

for example 

ABC - 3333333333

result in search ABC is fine but when i put 33333333 its not come on search 



what i done


````

@api.model 

 def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): 

 if operator in ('ilike', 'like', '=', '=like', '=ilike'): 

 args = expression.AND([ args or [], ['|', ('visitor.id_proof_no', operator, name), ('visitor', operator, name)] ]) 

 return super(VisitDetails, self)._name_search(name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid)


```


its not  working where i'm wrong pls correct me 

Avatar
Discard
Author Best Answer

@api.multi
def name_get(self):
result = []
for prod in self:
result.append((prod.id, "%s - %s" % ( prod.name, prod.id_proof_no or '')))
return result

@api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
args = args or []
if operator == 'ilike' and not (name or '').strip():
domain = []
else:
domain = ['|', ('name', 'ilike', name), ('id_proof_no', 'ilike', name)]
sat_code_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
return self.browse(sat_code_ids).name_get()

Avatar
Discard
Best Answer

1. Why you inherit _name_search (private method) and not name_search?

2. See this part of code in models.py _name_search: 

if not self._rec_name:
_logger.warning("Cannot execute name_search, no _rec_name defined on %s", self._name)
elif not (name == '' and operator == 'ilike'):
args += [(self._rec_name, operator, name)]

UPDATED:

Simmilar solution in account_invoice.py:

@api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
  args = args or []
  invoice_ids = []
  if name:
    invoice_ids = self._search([('number', '=', name)] + args, limit=limit, access_rights_uid=name_get_uid)
  if not invoice_ids:
   invoice_ids = self._search([('name', operator, name)] + args, limit=limit, access_rights_uid=name_get_uid)
  return self.browse(invoice_ids).name_get()


Avatar
Discard
Author

```

@api.multi

def name_get(self):

result = []

for record in self:

name = record.name + ' - ' + str(record.id_proof_no)

result.append((record.id, name))

return result

@api.model

def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):

args = args or []

if operator == 'ilike' and not (name or '').strip():

domain = []

else:

domain = ['|', ('name', 'ilike', name), ('id_proof_no', 'ilike', name)]

sat_code_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)

return self.browse(sat_code_ids).name_get()

```

Author

still not working

is possible testing _search and browse with sudo()?

Related Posts Replies Views Activity
0
Dec 21
1340
3
Jun 19
2879
2
Dec 23
11994
0
Oct 23
33
3
Oct 23
787