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

Filter a list of clients (model res.partner)

By
Val Kinyock
on 6/2/15, 12:01 PM 1,462 views

I would like to filter my clients in a view and only list clients that have services (a custom module).

I tried a lot of things but my view keeps listing the whole and it drives me crazy.

My related view/action:

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

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

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

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

  <tree string="Contacts" edit="false" create="false" delete="false">

  <field name="got_services"/>

  <field name="display_name" domain="[('got_services', '=', True)]"/> 

  <button name="generate" type="object" string="Générer" icon="oe_highlight"/>

  </tree>

  </field>

  </record>


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

  <field name="name">Génération factures</field>

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

  <field name="view_mode">tree</field>

  <field name="view_id" ref="view_res_partner_tree" />

  <field name="domain">[('got_services', '=', True)]</field>

  </record>


My model inherited from res.partner:


class res_partner(models.Model):

 _name = 'res.partner'

 _inherit = 'res.partner'  

 got_services = fields.Boolean('Got services', compute='_compute_services') 

 @api.multi

 def _compute_services(self): 

     for record in self:

     self.env.cr.execute("SELECT * FROM module_service WHERE id = %d;" % record.id)

    res = self.env.cr.fetchall() 

    record.got_services = False if not res else True 

I even added this to mymodule_security.xml in /security

 <?xml version="1.0" encoding="utf-8"?>

  <openerp>

  <data noupdate="1">

  <record id="module_list_clients" model="ir.rule">

  <field name="name">Clients</field>

  <field name="model_id" ref="model_res_partner"/>

  <field name="global" eval="True"/>

  <field name="domain_force">[('got_services', '=', True)]</field>

  </record>

  </data>

  </openerp>


Whatever I try every single clients is printed even if my boolean is correctly set to True or False.
Do you guys have an idea please ?

Thanks

0

Hi there,

I'm clearly not a technical expert, but I wonder if this problem isn't related to storing the value of your field.

As explained in our documentation, under "computed fields" https://www.odoo.com/documentation/8.0/reference/orm.html:

computed fields are not stored by default, they are computed and returned when requested. Setting store=True will store them in the database and automatically enable searching

My guess is that not storing the result of the function won't allow you to search (and so to have a domain on the field)

Can you try and keep us aware of your findings?

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: 6/2/15, 12:01 PM
Seen: 1462 times
Last updated: 6/2/15, 2:47 PM