Name_search based on context don't work in o2m

Bug #290274 reported by Joël Grand-Guillaume @ camptocamp
4
Affects Status Importance Assigned to Milestone
Odoo Web Client
Fix Released
Undecided
Amit Mendapara

Bug Description

Name_search based on context don't work in o2m field.

If you add context tag on a tree view in o2m filed, this context is not pass to the name_search function. This is bad, cause it' very useful. You can for exemple make a filter on "activity" based on selected "account" in the line...

An exemple:

Here the field view definition in the tree part of o2m:

<field name="activity" context="account_id=account_id"/>

Here the name search of activity object:

 def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=80):
  if not args:
   args=[]
  acc_ids=[]
  if context.get('account_id',False):
   account_id=self.pool.get('account.analytic.account').browse(cr,uid,context.get('account_id',False))
   #take the account wich have activity_ids
   acc_who_matters=self._get_first_AA_wich_have_activity(cr,uid,account_id)
   if acc_who_matters:
    for i in acc_who_matters.activity_ids:
     acc_ids.append(i.id)
  if not context:
   context={}
  account = self.search(cr, uid, [('code', '=', name),('id','in',acc_ids)]+args, limit=limit, context=context)
  if not account:
   account = self.search(cr, uid, [('name', 'ilike', '%%%s%%' % name),('id','in',acc_ids)]+args, limit=limit, context=context)
  if not account:
   account = self.search(cr, uid, [('id','in',acc_ids)]+args, limit=limit, context=context)
  return self.name_get(cr, uid, account, context=context)

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

This mehtode of context definition doesn't work also:

<field name="activity" context="{'account_id': account_id}" />

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

It seems when I did a pdb.set_trace() that it call two times the name_search function... The first one work well and return desired result till display of search popup... But Popup re-call name_search to fullfil his info and this times context is empty, and values are returned...

Revision history for this message
Amit Mendapara (cristatus) wrote :

I have fixed the problem in trunk as well as branch 4.2. Please confirm whether it has solved your problem or not.

Changed in openobject-client-web:
assignee: nobody → mendapara-amit
status: New → In Progress
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote : Re: [Bug 290274] Re: Name_search based on context don't work in o2m

Hi,

It's ok for the call wich pass right the context now, but we still
have a problem I described here:

https://bugs.launchpad.net/openobject-client-web/+bug/296328

I found a solution (not sure it's the right one) and give a patch for.

Thanks to have a look and give me some feed-back.

Regards,

Joël

Le 6 nov. 08 à 14:14, Amit Mendapara a écrit :

> I have fixed the problem in trunk as well as branch 4.2. Please
> confirm
> whether it has solved your problem or not.
>
> ** Changed in: openobject-client-web
> Assignee: (unassigned) => Amit Mendapara (mendapara-amit)
> Status: New => In Progress
>
> --
> Name_search based on context don't work in o2m
> https://bugs.launchpad.net/bugs/290274
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in OpenObject Web Client: In Progress
>
> Bug description:
> Name_search based on context don't work in o2m field.
>
> If you add context tag on a tree view in o2m filed, this context is
> not pass to the name_search function. This is bad, cause it' very
> useful. You can for exemple make a filter on "activity" based on
> selected "account" in the line...
>
> An exemple:
>
> Here the field view definition in the tree part of o2m:
>
> <field name="activity" context="account_id=account_id"/>
>
> Here the name search of activity object:
>
> def name_search(self, cr, uid, name, args=None, operator='ilike',
> context=None, limit=80):
> if not args:
> args=[]
> acc_ids=[]
> if context.get('account_id',False):
>
> account_id
> =
> self
> .pool
> .get
> ('account
> .analytic.account').browse(cr,uid,context.get('account_id',False))
> #take the account wich have activity_ids
>
> acc_who_matters
> =self._get_first_AA_wich_have_activity(cr,uid,account_id)
> if acc_who_matters:
> for i in acc_who_matters.activity_ids:
> acc_ids.append(i.id)
> if not context:
> context={}
> account = self.search(cr, uid, [('code', '=', name),
> ('id','in',acc_ids)]+args, limit=limit, context=context)
> if not account:
> account = self.search(cr, uid, [('name', 'ilike', '%%%s%%' %
> name),('id','in',acc_ids)]+args, limit=limit, context=context)
> if not account:
> account = self.search(cr, uid, [('id','in',acc_ids)]+args,
> limit=limit, context=context)
> return self.name_get(cr, uid, account, context=context)

--

Joël Grand-Guillaume
OpenERP Consultant
Business Solutions

Camptocamp SA
PSE A, CH-1015 Lausanne
  www.camptocamp.com

Phone: +41 21 619 10 28
Office: +41 21 619 10 10
Fax: +41 21 619 10 00
Email: <email address hidden>

P Please consider the environment before printing this email

Changed in openobject-client-web:
status: In Progress → Fix Committed
Changed in openobject-client-web:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.