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

Hy,

I would like to filter datas with domain action and current company_id.
I tried many thinks without success :

<record id="action_tasks" model="ir.actions.act_window">
        <field name="name">tasks</field>
        <field name="res_model">project.task</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{}</field>
        <field name="domain" >[('company_id','!=',context.get('company_id',False))]</field>
        </record>

More generally how to create an action linked on a menu that is filtered on current company.
Is there any way to dynamically associate the menu to an action and return a filtered action_window?

Thanks

อวตาร
ละทิ้ง

In another way to Filter record using Record Rule

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

I tested it on runbot => no success ccould it be a bug?

อวตาร
ละทิ้ง

I have the same problem. Ho add mandatory filter for company_id?

Hy Ray, thanks fro reading my post, unfortunately, I have this message name : ``` NameError: name 'user' is not defined

Thanks to @Ray and @atchuthan for advice. It works implemented in rule. Small drawback is that this setting does not apply to the admin. Only an ordinary user has limited access to the data filtered by "company_id" rule.

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

<field name="domain">[('company_id','=',allowed_company_ids[0])]</field>

อวตาร
ละทิ้ง

look like this solution doesn't work on record rule.

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

We already have a rule available for Project Task that was done for Multi-company

    <record model="ir.rule" id="task_comp_rule">
        <field name="name">Project/Task: multi-company</field>
        <field name="model_id" ref="model_project_task"/>
        <field name="global" eval="True"/>
        <field name="domain_force">['|',
                                        ('company_id', '=', False),
                                        ('company_id', 'child_of', [user.company_id.id]),
                                    ]</field>
    </record>

So, your requirement is to show the record for that particular company and not all its child company.  Then you need to change the RULE

<field name="domain_force">['|',
                                        ('company_id', '=', False),
                                        ('company_id', '=', [user.company_id.id]),
                                    ]</field>

But, functionally making this change is a wrong move.

อวตาร
ละทิ้ง

I'm migrating from odoo11 to odoo12.

This domain works in odoo11 But not in odoo12 , Any Idea?

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

    [ ("company_id", "=", base.main_company) ] if you rely on only one company (this usually works).

Is there any way to dynamically associate the menu to an action and return a filtered action_window?

Override the search method in your model.

Check also https://www.odoo.com/forum/help-1/question/how-to-append-a-domain-with-to-existing-domain-58308#answer-58389.

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

[ ("company_id", "=", user.company_id.id) ]

อวตาร
ละทิ้ง

I tried but result is

Uncaught Error: NameError: name 'user' is not defined

Same in model="ir.actions.act_window">