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

how to filter many2one field

By
philip
on 9/10/14, 2:50 AM 3,884 views

Can OpenERP/Odoo7 handle filter many2one field per user access.

Fields:
client = many2one
account = many2one
branch = many2one
description
code
price
date

from the above simple fields, let say if you select one of the client from CLIENT field you should only see all ACCOUNT from that client and Branch each account please see below diagram:

CLIENT:
---Client1
------Account1
---------Branch1
---------Branch2
------Account2
---------Branch1
---------Branch2
------Account3
---------Branch1
---------Branch2
---Client2
------Account4
---------Branch1
---------Branch2
------Account5
---------Branch1
---------Branch2
------Account6
---------Branch1
---------Branch2

Please help me on how to achieve this, I dont know where I start.

If anyone can help it would be greatly appreciated.

class test_product(osv.Model):
    _name = "test.product"
    _columns = {
        'client_id': fields.many2one('client', 'Client Name'),
        'accounts_id': fields.many2one('accounts', 'Account Name'),
        'branch_id': fields.many2one('branch','Branch Name'),
    }

class client(osv.Model):
    _name = "client"
    _columns = {
        'client': fields.char('Client Name', size=32),
    }

class accounts(osv.Model):
    _name = "accounts"
    _columns = {
        'accounts': fields.char('Account Name', size=32),
        'client_id': fields.many2one('client', 'Client'),
        }
    
class branch(osv.Model):
    _name = "branch"
    _columns = {
        'branch': fields.char('Branch Name', size=32),
        'accounts_id': fields.many2one('accounts', 'Account'),
        }

    <record model="ir.actions.act_window" id="test_product_submenu_action">
        <field name="name">Products</field>
        <field name="res_model">test.product</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">Click Create to add a new Codetest record.</p>
        </field>        
    </record>

    <record id="test_product_form_view" model="ir.ui.view">
        <field name="name">test.product.form.vew</field>
        <field name="model">test.product</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Product">
                <field name="client_id"/>
                <field name="accounts_id" domain="[('client_id', '=', client_id)]"/>
                <field name="branch_id"/>
            </form>
        </field>
    </record>

<menuitem id="test_product" name="Test Product" />
<menuitem id="test_product_menu" name="Test Product" parent="test_product"/>
<menuitem id="test_product_submenu" name="Product" parent="test_product_menu"  action="test_product_submenu_action"/>

1
Deviprasad V
On 9/10/14, 5:47 AM

Hi Philip,
You can set a domain inside the account field

<field name='client_id'/>

<field name='account_id' domain="[('client_id', '=', client_id)]/>

Thank you very much

philip
on 9/10/14, 8:22 AM

Is it is resolved your problem

Deviprasad V
on 9/11/14, 12:19 AM

no sir nothing happened to my fields, could you please give me some more info to achieve this

philip
on 9/15/14, 2:33 AM

I have post my python code and xml above.

philip
on 9/15/14, 3:01 AM

Hi Philip, There is no relation inside these three tables. And you want to change the type fields in "test_product" class to "many2one". Then you can domain these

Deviprasad V
on 9/15/14, 3:14 AM

Change your code like this Python code---- class test_product(osv.Model): _name = "test.product" _columns = { 'client_id': fields.many2one('client', 'Client Name'), 'accounts_id': fields.many2one('accounts', 'Client Name'), 'branch_id': fields.many2one('branch','Client Name'), } class client(osv.Model): _name = "client" _columns = { 'client': fields.char('Client Name', size=32), } class accounts(osv.Model): _name = "accounts" _columns = { 'accounts': fields.char('Account Name', size=32), 'client_id':fields.many2one('client', 'Client'), } class branch(osv.Model): _name = "branch" _columns = { 'branch': fields.char('Branch Name', size=32), 'account_id':fields.char('accounts', 'Account'), } XML--- test.product Test form Product test.product form tree,form

Deviprasad V
on 9/15/14, 11:03 AM

The logic is working, but after when entering value to my field let say when I entered value = CLIENTTEST to my field client, then hit Save button the client field value became client,1 instead of a CLIENTTEST likewise to accounts (accounts,1) and branch (branch,1). I modified my python code and xml above, please see.

philip
on 9/17/14, 9:58 PM

is working now thanks for all your help

philip
on 9/21/14, 11:35 PM

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

1 follower(s)

Stats

Asked: 9/10/14, 2:50 AM
Seen: 3884 times
Last updated: 3/31/16, 7:01 AM