[7.0] Invalid field in "quick add" pop up

Asked by Andrew

How do I reprogram the "quick add" dialog box that pops up when you have a selection, but item you want to select does not exist.

 def _grade_get(self, cr, uid, context=None):
  grade_obj = self.pool.get('product.vars.grade')
  grade_ids = grade_obj.search(cr, uid, [], order='grade')
  grade_types = grade_obj.read(cr, uid, grade_ids, ['id','grade'], context=context)

  res = []

  for record in grade_types:
   res.append((record['id'],record['grade'],))
  return res

 _columns = {
  'grade': fields.many2one('product.vars.grade', 'grade', selection=_grade_get, required=True),
)

I get the following error:

Server Traceback (most recent call last):
  File "/opt/openerp/web/addons/web/session.py", line 90, in send
    return openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/opt/openerp/server/openerp/netsvc.py", line 295, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/opt/openerp/server/openerp/service/web_services.py", line 614, in dispatch
    res = fn(db, uid, *params)
  File "/opt/openerp/server/openerp/osv/osv.py", line 169, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/opt/openerp/server/openerp/osv/osv.py", line 123, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/opt/openerp/server/openerp/osv/osv.py", line 179, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/opt/openerp/server/openerp/osv/osv.py", line 166, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/opt/openerp/server/openerp/osv/orm.py", line 2397, in name_search
    return self._name_search(cr, user, name, args, operator, context, limit)
  File "/opt/openerp/server/openerp/osv/orm.py", line 2428, in _name_search
    ids = self._search(cr, user, args, limit=limit, context=context, access_rights_uid=access_rights_uid)
  File "/opt/openerp/server/openerp/osv/orm.py", line 4843, in _search
    query = self._where_calc(cr, user, args, context=context)
  File "/opt/openerp/server/openerp/osv/orm.py", line 4674, in _where_calc
    e = expression.expression(cr, user, domain, self, context)
  File "/opt/openerp/server/openerp/osv/expression.py", line 632, in __init__
    self.parse(cr, uid, context=context)
  File "/opt/openerp/server/openerp/osv/expression.py", line 806, in parse
    raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
ValueError: Invalid field 'name' in leaf "<osv.ExtendedLeaf: ('name', 'ilike', 'product.vars.grade,') on product_vars_grade (ctx: )>"

I can get the error to go away if I add the column "name" to "product.vars.grade" but I don't want to use that column .

Where is the code that is referenced when you click inside of a many2one and openERP searches gives you the option to create an entry if it doesn't already exist?

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Stefan Rijnhart (Opener)
Solved:
Last query:
Last reply:
Revision history for this message
Best Stefan Rijnhart (Opener) (stefan-opener) said :
#1

If your model does not have a 'name' field, change the following property accordingly.

    _rec_name = 'grade'

http://doc.openerp.com/v6.1/developer/03_modules_2.html?highlight=_rec_name

Revision history for this message
Andrew (aes) said :
#2

Thanks Stefan Rijnhart (Therp), that solved my question.

Revision history for this message
Andrew (aes) said :
#3

This is great, it worked 99% there is still a minor issue with formatting.

The selection box and the quick add box do not respect the 3 character limit of the field. You can type as many characters as you like and when you save, the field is silently truncated to 3 characters.

How can I get the selection field to respect the character limit of the data base field?