Odoo Help

0

0
5 Answers
0
Avatar

Usman Farzand

--Usman Farzand--

5069
| 6 3 7
Faisalabad, Pakistan
--Usman Farzand--

I Love Programming ....


E-Mail At

usman_farzand@outlook.com

Usman Farzand
6/13/19, 7:33 AM

@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()

1
Avatar

Zbik

--Zbik--
12143
| 7 6 9
Łódź, Poland
--Zbik--


Zbik
6/13/19, 6:24 AM

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()


3 Comments
Usman Farzand
6/13/19, 6:30 AM

```

@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()

```

Usman Farzand
6/13/19, 6:30 AM

still not working

Zbik
6/13/19, 6:57 AM

is possible testing _search and browse with sudo()?

Ask a Question
Writer
Tags
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now