コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
17907 ビュー

Hi,

I am having a domain filter for object res.partner like the below in contacts_view.xml

    <field name="domain">[('department_id','=',context.get('dept'))]</field>

I would like to do the following

  • Get the current user object (my res_user object has id & dept)
  • i would get the id from context as it's stored by default by session. i like to get the dept from the context

I've tried this already

from openerp.osv import fields,osv
from openerp.tools.translate import _
from decimal import Context

class res_partner(osv.osv):
_name = "res.partner"
_inherit = 'res.partner'

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    res = super(res_partner,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
    if context is None:
        context={}

    context.update({
        'dept': 1
    })
    res.update({
        'context' : context,
    })
    return res     
res_partner()

Still in the filter i am unable to get the dept value from context.

How to get the department from the user object in xml? or how to use the python function in xml? This prob is really annoying me so much. Thanks a lot for your time.

アバター
破棄
最善の回答

You should update the context before calling super so it will looks like:

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    if context is None:
        context={}

    context.update({
        'dept': 1
    })
    return super(res_partner,self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
アバター
破棄
著作者

Hi nazeril, thanks for your reply. Still having the same problem. Can you guess wht went wrong?

You can always update domain from context by modifying search method of model. Besides, my name is Nazarii, not nazeril!!!

最善の回答

Hi. I am not a python giant :-) So sorry for advance if this is not good, but I want to share with you...

idk = context.get('active_id',False) >> return idk as integer

idk = context.get('active_ids',False) >> return idk as list

in this case for id in idk: use id for something

so may be... :-) :

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    res = super(res_partner,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
    if context is None:
        context={}
    idk = context.get('active_ids',False)  # return idk as list
    for id in idk:
    #your object manipualtion according by id
アバター
破棄