Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
11 ตอบกลับ
29045 มุมมอง

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"/>

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

Is it is resolved your problem

ผู้เขียน

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

ผู้เขียน

I have post my python code and xml above.

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

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

ผู้เขียน

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.

ผู้เขียน

is working now thanks for all your help

คำตอบที่ดีที่สุด

i had similary problem and i solve it by this method in following link:

https://stackoverflow.com/questions/45816652/dependent-drop-down-list-in-odoo-8-open-erp?answertab=active#tab-top

อวตาร
ละทิ้ง