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

Toggle <field>'s visibility in search view

By
Anton Chepurov
on 7/21/14, 9:33 AM 1,188 views

Is there a way to toggle a <field> visible/invisible, e.g. by using a marker filter?

The goal is to be able to turn on/off m2o field's auto-completion/auto-suggestion on demand, ideally using another dummy filter for that.

1

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 7/21/14, 10:12 AM

Why don't you define domain in the field to filter record in auto-completion.
 

0
Anton Chepurov
On 7/21/14, 4:55 PM

Hey Ben,
Many thanks for the hint!

Although using domain to completely disable search field was not quite an intuitive solution (more of a hack), it worked like a charm, indeed! While neither <code>invisible</code>, nor <code>attrs</code> attributes could fetch the changed context, <code>domain</code> attribute was indeed the only one that could access the context.

Here is the complete solution, in case somebody will need it in the future:

XML, search view:
<pre><code>
  <filter string="Disable Autocomplete" name="perm_speedup" context="{'disable_autocomplete': '='}"/>
  <field name="product_id" position="attributes">
      <attribute name="domain">[('id', context.get('disable_autocomplete', '!='), 0)]</attribute>
  </field>
  <field name="product_code" string="Product Exact" filter_domain="[('product_code', '=', self)]"/>
  <field name="product_code"/>
</code></pre>

Python:
<pre><code>
  'product_code': fields.related('product_id', 'default_code', string='Product', type='char', readonly=True),
</code></pre>

Description:
'Disable Autocomplete' filter is turned on by default (in act_window, context={'search_default_perm_speedup':1}).
This allows to quickly type in the desired product code, without waiting for the suggestions to load.
'Product Exact' is used with copy-paste codes or with barcode scanner.
'Product' (default) is used to search for partial codes.
Of course, 'Disable Autocomplete' marker-filter can be turned off when needed.

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: 7/21/14, 9:33 AM
Seen: 1188 times
Last updated: 3/16/15, 8:10 AM