help me on search view, active filter

Asked by Cuong

Hi,

I've made a search view with filter 'active' as below. But in tree view, there are no effects when clicking on Active button. My class has a field named 'active' of type boolean.
            <search string="Test">
                <filter domain="[('active','=',True)]" name="active" string="Active"/>
            </search>

I'd like to have a behavior that filters active records if this button is pressed.

Thanks,

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

Revision history for this message
Cuong (bhcuong2008) said :
#1

If I change from True to False like this
            <search string="Test">
                <filter domain="[('active','=',False)]" name="active" string="Active"/>
            </search>

Then it works in reverse order. it means when clicked, it displays 'inactive' records. Normally it displays active records.

Revision history for this message
filsys (office-filsystem) said :
#2

1. 'active' field is a special field in class who tell to the view to
hide record.
2. If you use filter domain="[('active','=',True)]" this is like you
don't use any filter.
3. you can use alse simply <field name="active"/> and you will see a
select widget in filter zone of the list.
Thanks

On 13.05.2011 08:00, Cuong wrote:
> Question #157305 on OpenERP Server changed:
> https://answers.launchpad.net/openobject-server/+question/157305
>
> Cuong gave more information on the question:
> If I change from True to False like this
> <search string="Test">
> <filter domain="[('active','=',False)]" name="active" string="Active"/>
> </search>
>
> Then it works in reverse order. it means when clicked, it displays
> 'inactive' records. Normally it displays active records.
>

Revision history for this message
Cuong (bhcuong2008) said :
#3

Hi filsys,

I take the code from hr.employee search view. In employee form, when you check 'Active', then it appears in tree view. When you uncheck 'Active' option, it will disappear in tree view.

About your step 3, could you tell me details, if possible, please give me an example.

Thank you very much.

Revision history for this message
Naresh(OpenERP) (nch-openerp) said :
#4

Hi Cuong,

If you want the same thing as in your comment #3 then you just need to add your field to the tree view with "invisible" =True attribute. then you can also see the field when you press the active button and disappear when you depress it.

Hope this helps !

Thanks

Revision history for this message
Cuong (bhcuong2008) said :
#5

Hi Naresh,

I wonder about case of hr.employee. In the class definition, I found no field named 'active'. But in the form view of hr.employee, this field is added to the form. Also it is used inside its search view.

I do the same as hr.employee, except I can't find definition of 'active' field in hr.employee.

Following your comment #4,
- what must I define in search view?
- in tree view, I add this field like this
          <field name='active' invisible="true">
          is it right?

Thank you very much,

Revision history for this message
Naresh(OpenERP) (nch-openerp) said :
#6

Hi Cuong,

"Active " field is a predefined field in OpenERP . So you dont need to redefined it. you can use it whenever and where ever you want..

for my comment #4 I need to make this clear that the field will be added in tree view only in groupby environment. eg: If you have a group by button in your search view and that field is added in tree view with invisible attribute.then when you group on that field the field will be visible and ungroup then the field will be invisible in the tree view.

For the filters as in your case this want work.

ok now if you simply want to add the filter button for "active" then this is what you need to add in your search view
 <filter icon="terp-personal+" domain="[('active','=',True)]" name="active" string="Active" />

So when pressed the active records will be seen. if you depressed all records will be seen

Thanks !

Revision history for this message
Cuong (bhcuong2008) said :
#7

Hi Naresh,

I understand now. I'm gonna try it now.

Thank you very much,

Revision history for this message
Cuong (bhcuong2008) said :
#8

Thanks Naresh(OpenERP), that solved my question.

Revision history for this message
Cuong (bhcuong2008) said :
#9

One more question,

in postgres db, I can't find the field 'active'. Where is it defined?

Thank you.

Revision history for this message
Cuong (bhcuong2008) said :
#10

One more question,

in postgres db, I can't find the field 'active'. Where is it defined?

Thank you.

Revision history for this message
OpenBMS JSC (openbmsjsc) said :
#11

'active' is a special field, define in the OpenObject ORM model (osv.osv)

Revision history for this message
filsys (office-filsystem) said :
#12

... in postgres db (for hr_employee table for example) is field active
with data type boolean.
Thanks

On 13.05.2011 09:05, Cuong wrote:
> Question #157305 on OpenERP Server changed:
> https://answers.launchpad.net/openobject-server/+question/157305
>
> Status: Solved => Open
>
> Cuong is still having a problem:
> One more question,
>
> in postgres db, I can't find the field 'active'. Where is it defined?
>
> Thank you.
>

Revision history for this message
Cuong (bhcuong2008) said :
#13

Hi Naresh,

Now I remove field 'active' in my class. In coding, how can I get all fields with value active='True' for calculation?

In my case, openERP gives me error that the field 'active' in my class does not exist. my code can't run.

Thank you,

Revision history for this message
Naresh(OpenERP) (nch-openerp) said :
#14

Hello Cuong,

'Active' is a predefined field in OpenERP. right so OpenERP uses this field while performing different operation on a model like search,read etc.. only if that field is not available in the model. If you explicitly add this field in your model then Openerp will filter out all inactive records unless they were explicitely asked for...So like you said you need in the calculation the value of field active then you need to have it in your model other wise openERP will give you missing field in model sort of error...

Hope this helps you !

Thanks !

Revision history for this message
Cuong (bhcuong2008) said :
#15

Hi Naresh,

Following your advice, I remove active field in my class, and other places. Now in the view, form and tree, although I define <field name="active" />, but it disappears in browser.

in my class, there's definition of active field anymore, and in other functions that use it:
===
class hr_tax_rate(osv.osv):
    '''
    Personal Income Tax Rate
    '''

    _name = 'hr.tax.rate'
    _description = 'Personal Income Tax Rate Declaration'
    _order = 'sequence'
    _columns = {
      .....
      ....
      ....
    }
    _defaults = {
        ....
        ....
    }
===

In form view:
 <field name="active"/>

In search view:
             <search string="Tax Rates">
                <filter icon="terp-personal+" domain="[('active','=',True)]" name="active" string="Active" />
            </search>

That's all I test active field. The result is that no "Active" checkbox appears in browser.

Thank you very much.

Revision history for this message
Cuong (bhcuong2008) said :
#16

Hi Naresh,

As your comment #4, you mean that active field can't be used in search method. I mean that
self.search(cr, uid, [('active' ,=, 'True')]) can't be used? Is it right?

Thank you very much.

Revision history for this message
Cuong (bhcuong2008) said :
#17

Hi Naresh,

I correct my comment #15. I define <field name="active"/>, and in the browser, when I switch to form view, it gives error as below.

===
Can't find field 'active' in the following view parts composing the view of object model 'hr.tax.rate': * hr.tax.rate.form Either you wrongly customized this view, or some modules bringing those views are not compatible with your current data model
===

I wonder why this issue occurs while you told me that we can use it anywhere, anytime without defining it in class.

Thank you very much.

Revision history for this message
Cuong (bhcuong2008) said :
#18

In the case of hr.py, class hr.employee, I found it very special. It doesn't define 'active' field in _column, but in _defaults, it is defined without any complaint. I do the same for my class, but it prompts error. It's really strange.

Revision history for this message
Cuong (bhcuong2008) said :
#19

In hr.employee, it displays all employees by default in tree view. When click on Active, it displays only active employees. This behavior is opposite from my case.

I'm very confused now.

Can you help with this problem?

Provide an answer of your own, or ask Cuong for more information if necessary.

To post a message you must log in.