Filtering one2many field by a many2many field

Asked by ginsmar

Hello.

I want to filter a one2many field by a domain that is a list of ids, resulting of a many2many field.
But it doesn't work.
My english is not very good, better an example:

class test_01(osv.osv):
    _name = 'test_01'
    _description = 'Test 01'

    _columns = {
        'name': fields.char('Name', size=64, required=True, select=True),
        'product_id': fields.many2one('product.product', 'Product', required=True),
        'product_category_ids': fields.many2many('product.category',
            'test_01_product_categ_rel', 'product_categ_id','operation_type_id',
            'Product Categories'),
    }
test_01()

And this in the xml view file the domain:
        <field name="product_id" domain="[('categ_id', 'in', product_category_ids)]" />

This code fails:
[2010-01-08 20:42:40,046] DEBUG_RPC:service:'object'
[2010-01-08 20:42:40,047] DEBUG_RPC:method:'execute'
[2010-01-08 20:42:40,050] DEBUG_RPC:params:[01]: ('lazarus_506_01',
[2010-01-08 20:42:40,050] DEBUG_RPC:params:[02]: 1,
[2010-01-08 20:42:40,051] DEBUG_RPC:params:[03]: '231425',
[2010-01-08 20:42:40,051] DEBUG_RPC:params:[04]: 'product.product',
[2010-01-08 20:42:40,052] DEBUG_RPC:params:[05]: 'name_search',
[2010-01-08 20:42:40,052] DEBUG_RPC:params:[06]: '',
[2010-01-08 20:42:40,053] DEBUG_RPC:params:[07]: [('categ_id', 'in', [(6, 0, [5])])],
[2010-01-08 20:42:40,053] DEBUG_RPC:params:[08]: 'ilike',
[2010-01-08 20:42:40,053] DEBUG_RPC:params:[09]: {'active_id': False,
[2010-01-08 20:42:40,054] DEBUG_RPC:params:[10]: 'active_ids': [],
[2010-01-08 20:42:40,054] DEBUG_RPC:params:[11]: 'client': 'web',
[2010-01-08 20:42:40,055] DEBUG_RPC:params:[12]: 'lang': u'es_ES',
[2010-01-08 20:42:40,055] DEBUG_RPC:params:[13]: 'tz': False})
[2010-01-08 20:42:40,059] DEBUG:sql:bad query: None
[2010-01-08 20:42:40,060] DEBUG:sql:not all arguments converted during string formatting

It fails because the value of product_category_ids is [(6, 0, [5])] instead of a id's list.

Any solution to this problem?

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Vinay Rana (OpenERP)
Solved:
Last query:
Last reply:
Revision history for this message
Best Vinay Rana (OpenERP) (vra-openerp) said :
#1

Hello,

Try with the following code:

        <record id="view_test_form" model="ir.ui.view">
            <field name="name">test.form</field>
            <field name="model">test_01</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Test">
                    <field name="name" select="1"/>
                    <field name="product_id" domain="[('categ_id', 'in', product_category_ids[0][2])]"/>
                    <field colspan="4" name="product_category_ids" nolabel="1"/>
                </form>
            </field>
        </record>

It will Solve your problem.
Hope This will help you.
Thanks.

Revision history for this message
ginsmar (ginsmar) said :
#2

It works. Thanks!!!!!

2010/1/11 vra (openerp) <email address hidden>

> Your question #96707 on OpenObject Server changed:
> https://answers.launchpad.net/openobject-server/+question/96707
>
> Status: Open => Answered
>
> vra (openerp) proposed the following answer:
> Hello,
>
>
> Try with the following code:
>
> <record id="view_test_form" model="ir.ui.view">
> <field name="name">test.form</field>
> <field name="model">test_01</field>
> <field name="type">form</field>
> <field name="arch" type="xml">
> <form string="Test">
> <field name="name" select="1"/>
> <field name="product_id" domain="[('categ_id', 'in',
> product_category_ids[0][2])]"/>
> <field colspan="4" name="product_category_ids"
> nolabel="1"/>
> </form>
> </field>
> </record>
>
>
> It will Solve your problem.
> Hope This will help you.
> Thanks.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
>
> https://answers.launchpad.net/openobject-server/+question/96707/+confirm?answer_id=0
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/openobject-server/+question/96707
>
> You received this question notification because you are a direct
> subscriber of the question.
>

Revision history for this message
ginsmar (ginsmar) said :
#3

Thanks vra (openerp), that solved my question.