Odoo Help

Welcome!

This community 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.

0

Filter many2one field with functional field

By
Sahib Hasanov
on 1/24/14, 7:20 AM 4,094 views

I try filter list of values in dropdown list of many2one field (this field is in tree). For this I've created functional field which return list of allowed ids. In xml file i used domain with in condition. Here's my code

In py file

class cm_order_line(osv.osv):
_name = 'cm.order.line'

def _get_order_ids(self, cr, uid, ids, field_names=None, arg=None, context=None):
task_order_ids = [5,9,10]    # only as simplification...
return task_order_ids

_columns = {
'order_id': fields.many2one('stock.picking', 'Order Name'),
'order_ids': fields.function(_get_order_ids, type='char', string='Orders IDs', store=False),

_defaults = {
'order_ids': _get_order_ids
}

In XML

<field name="order_ids" invisible="1"/>
<field name="order_id" on_change="onchange_order_id(order_id)" domain="[('type','=','out'),('id', 'in', order_ids)]"/>

Everything works fine when i create new record. Domain works normal but after save (or when i just want to open inserted records) it gives error

AttributeError: 'list' object has no attribute 'get'

These are not the same, as Sahib needs to provide a list of IDs, not a single ID...

Mario Arias Badila
on 1/29/14, 1:52 AM
0

Jagdish Panchal

--Jagdish Panchal--
2674
| 5 3 6
Gandhinagar, India
--Jagdish Panchal--

OpenERP Developer

Jagdish Panchal
On 5/15/14, 9:07 AM

Hi,

Yor passing "order_ids" field domain xml file but its function field and not stored in data base thats why you facing this error.

Thank

0
GHADHOUN Azer
On 2/19/15, 8:22 AM

change type='char', to type='many2one',
This will work

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 1/24/14, 7:20 AM
Seen: 4094 times
Last updated: 3/16/15, 8:10 AM