Odoo Help


How do I return the partner website? [Closed]

AJ Schrafel Paper Corp
on 6/8/13, 11:31 PM 2,334 views

The Question has been closed

AJ Schrafel Paper Corp
on 06/10/2013 14:59:02

I want to return the website for a partner in a custom module. I have written the following code to return the website, but I do not understand why it is not working.

The field is defined here:

'website': fields.function(_get_website, type="string", string='Website', store=False),

And here is the function:

def _get_website(self, cr, uid, ids, partner_id, args, context=None):
    partner_obj = self.pool.get('res.partner')
    for record in self.browse(cr, uid, ids, context=context):
        res[record.id] = {}
        website_ids=partner_obj.search(cr, uid, [('partner_id','=',record.partner_id.id)])
        res[record.id] = website_ids[0].website
    return res

I get the following Error: Client Traceback (most recent call last):

  File "/opt/openerp/web/addons/web/http.py", line 204, in dispatch
    response["result"] = method(self, **self.params)
  File "/opt/openerp/web/addons/web/controllers/main.py", line 1121, in call_kw
    return self._call_kw(req, model, method, args, kwargs)
  File "/opt/openerp/web/addons/web/controllers/main.py", line 1107, in _call_kw
    records = req.session.model(model).read(*args, **kwargs)
  File "/opt/openerp/web/addons/web/session.py", line 42, in proxy
    result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw)
  File "/opt/openerp/web/addons/web/session.py", line 30, in proxy_method
    result = self.session.send(self.service_name, method, *args)
  File "/opt/openerp/web/addons/web/session.py", line 103, in send
    raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)

Server Traceback (most recent call last):

  File "/opt/openerp/web/addons/web/session.py", line 89, in send
    return openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/opt/openerp/server/openerp/netsvc.py", line 292, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/opt/openerp/server/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/opt/openerp/server/openerp/osv/osv.py", line 188, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/opt/openerp/server/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/opt/openerp/server/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/opt/openerp/server/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/opt/openerp/server/openerp/osv/orm.py", line 3604, in read
    result = self._read_flat(cr, user, select, fields, context, load)
  File "/opt/openerp/server/openerp/osv/orm.py", line 3724, in _read_flat
    res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res)
  File "/opt/openerp/server/openerp/osv/fields.py", line 1131, in get
    result = self._fnct(obj, cr, uid, ids, name, self._arg, context)
  File "/opt/openerp/addons/base_report_to_fax/faxing.py", line 199, in _get_website
    website_ids=partner_obj.search(cr, uid, [('partner_id','=',record.partner_id.id)])
  File "/opt/openerp/server/openerp/osv/orm.py", line 2354, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/opt/openerp/server/openerp/addons/base/res/res_partner.py", line 579, in _search
    count=count, access_rights_uid=access_rights_uid)
  File "/opt/openerp/server/openerp/osv/orm.py", line 4845, 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 640, in __init__
    self.parse(cr, uid, context=context)
  File "/opt/openerp/server/openerp/osv/expression.py", line 804, in parse
    raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
ValueError: Invalid field 'partner_id' in leaf "<osv.ExtendedLeaf: ('partner_id', '=', 33198) on res_partner (ctx: )>"

What am I doing wrong?

update: answered -

    def _get_website(self, cr, uid, ids, partner_id, args, context=None):
        context = {}
        partner_obj = self.pool.get('res.partner') ids, context=context).partner_id)])
        for record in self.browse(cr, uid, ids, context=context):
            res[record.id] = {}
            website_ids=partner_obj.search(cr, uid, [('id','=',record.partner_id.id)])
            for website_brw in partner_obj.browse(cr, uid, website_ids, context=context):
                res[record.id] = website_brw.website
        return res


| 4 4 8
Ahmedabad, India

Odoo Expert

On 6/9/13, 2:07 AM

It gives you error because by search method always returns list of ids or empty list so here you are trying to access its fields, it is not the browse object.

Try with this

Instead of

res[record.id] = website_ids[0].website


for website_brw in partner_obj.browse(cr, uid, website_ids):
    res[record.id] = website_brw.website


I have seen this behaviour in the past, but I don't know why the for-loop is working, while the search or browse is not working. I'll post a question about it in the near future.

on 6/9/13, 7:56 PM

thank you this worked.

AJ Schrafel Paper Corp
on 6/10/13, 2:56 PM

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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/8/13, 11:31 PM
Seen: 2334 times
Last updated: 3/16/15, 8:10 AM