Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
52260 Widoki

Hi, I have inherited res.partner in my python code and added a boolean field called is_investor, which tells us that the partner is an 'investor'.

In XML in base.view_partner_tree, which displays all the types of partners, I want to display only those records for whom is_investor is true.

I tried to add a domain like "[('is_investor', '=', True)]" to the 'display_name' field but it didn't work because Odoo is still taking the original parent view definition.

Here is my code:

  <record id="base_view_partner_tree" model="ir.ui.view">       
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_tree"/>
            <field name="arch" type="xml">
                <field name="display_name" domain="[('is_investor', '=', True)]"/>

            </field>                       
        </record>

Despite this code, it is still showing me all of the partners including customers, suppliers, etc. I only want to see investors in this Tree view.

Can someone tell me how to add this domain successfully?

Awatar
Odrzuć
Autor Najlepsza odpowiedź

Thanks for the answer. I figured it out.

I inherited the search view of res.partner and added my own filter like this:


<record id="base_view_res_partner_filter" model="ir.ui.view">

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_res_partner_filter"/>

<field name="arch" type="xml">

<filter string="Salesperson" position="after">

<filter string="Investor" name="investor" domain="[('is_investor', '=', True)]"/>

</filter>

</field>

</record>


Then, in my corresponding action for 'investor' menu, I defined this line

<field name="context">{'search_default_investor':1}</field>


Note that the search_default_investor is named that way because the syntax is:

{'search_default_searchFilterName':1}

It should not be search_default_is_investor because is_investor is a field name not the name of a filter.


Someone reading this might also find this question useful:

https://www.odoo.com/forum/help-1/question/how-to-create-own-filter-and-apply-it-by-default-75280


Hope this helps someone. And thanks for the help Vasanth!

Awatar
Odrzuć
Najlepsza odpowiedź

you can use the search view instead of tree view for this


<search string=" ===="> 

<filter string="Investor" name="investor" icon="terp-personal" domain="[('is_investor','=','True')]" />

   </search>

By using this, you can find a filter in the search view called"Investor" and by clicking it, you can get only the records which the investor is true.

If you want this filter as default means, use this following code:


<record id="action_account_period_tree" model="ir.actions.act_window">

=====================

==========

<field name="context">{'search_default_investor': 1}</field>

  </record>


All the best


Awatar
Odrzuć

How to set domain in action view if i must get some value in function ?

Najlepsza odpowiedź

Hello Arjun,

You were adding domain at wrong place. If you want to limit your data by particular domain wise in list view then you shall add domain in Action. You can set Domain & Context accordingly as per need in Window Action. 

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
cze 24
2572
3
lis 20
6358
3
lip 25
9118
3
lip 25
4293
0
maj 25
877