Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
23591 Lượt xem

In a form view of a project.project model, I display related calendar.event records through a one2many field as a kanban

I'd like to filter that kanban view, but it doesn't work as described below.


On the form, I added the following field:

<field name="event_ids" mode="kanban"/>

The kanban shows up nicely on the form. Actually, a kanban view has been applied by default: the one that has the lowest sequence id.


As the system selected a kanban view, I assumed a search view is also applied by default.

The search view with the lowest sequence id is the following:

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

     <field name="name">calendar.event.mysearch</field>

     <field name="model">calendar.event</field>

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

        <search string="My search view">

            <field name="allday"/>

            <filter string="Full day events" name="filter_on_fullday" domain="[('allday','=',True)]"/>

         </search>

     </field>

</record>


If the search view would have been called from an action, I could have indicated a default filter in the act_window, like:

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


which made me think I could define a context on the field, like:

<field name="event_ids" mode="kanban" context="{'search_default_filter_on_fullday': 1}"/>


I must be missing something in my reasoning, because it doesn't work.

Maybe, no search view is selected by default. Can someone confirm?

How can I force a search view? And once a search view is applied, would it use the default filter?

If there is a search view, how can I tell the search view to execute the filter?

Thank you for your help.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Here is the solution.

In order to filter a one2many field on a form, the trick is to make a computed field, from the initial one2many field.

In my case, event_ids is the field I want to filter, in order to show only full day events.

In the model, I simply added a computed field, as follows:

    event_fullday_ids = fields.One2many('calendar.event', string='Full day events', compute='_get_event_fullday_ids')

And the function is:

    def _get_event_fullday_ids(self):
        self.event_fullday_ids = self.event_ids.search([('allday', '=', True)])

Then, instead of showing

<field name="event_ids" mode="kanban"/> on the form

I put this instead:

<field name="event_fullday_ids" mode="kanban"/>


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 12 15
3277
1
thg 7 19
10757
1
thg 1 24
1993
0
thg 6 21
2799
3
thg 9 17
7840