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

Override search method to Add/Remove domain in list view

By
Prakash
on 7/15/14, 9:17 AM 3,051 views

In Openerp 7  User login list view display record always with domain conditions. But while searching the record remove the domain condition temporarily and return the output based on user input. Based on search method overridden and below code used.

    <record id="action_custommodel_view" model="ir.actions.act_window">
        <field name="name">Sample</field>
        <field name="res_model">sample.module</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="view_id" ref="view_samplemodule_tree"/>
        <field name="domain">[('user_id','=',uid)]</field>
    </record>

def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None,count=False, extra=None):
        if uid == 1:
            del args[0]
        if len(args) == 1:
            user_domain = args[0]      
        if uid !=1 and len(args)>1:
            del args[0]
        if uid !=1 and not args:
            args.insert(0, user_domain)                                 
        return super(sample_one, self).search(cr, uid, args, offset, limit, order, context, count)

Let me know wheter about code is right or not?..

Please correct me if i am going wrong...

 

 

What is your problem? As long as your code worked, you can save the bill :D Some minor comment about hardcoded value, avoid it. You can use like SUPERUSER_ID to follow existing codebase.

Ben Bernard
on 7/23/14, 11:07 PM

One can override the 'search' method to get control on the displayed result in the tree view display, but this method should be overridden with cautious. For your current code, pls add a comment on each if conditions what does it mean, and a comment on the action you took when this condition is satisfied.

Tarek Mohamed Ibrahim
on 6/7/15, 6:44 AM

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

2 follower(s)

Stats

Asked: 7/15/14, 9:17 AM
Seen: 3051 times
Last updated: 6/7/15, 6:44 AM