Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
5587 Weergaven

Odoo 13 Enterprise Edition

Having created a User-defined filter that is shared to all users, I have edited it to include user_id = uid as follows:

["&","&","&",["customer_rank",">",0],["activity_ids","!=",False],["user_id","=", uid],["activity_date_deadline","=","2021-01-12"]]
When saving, I get the following error message: The domain you entered was not properly formatted.

I have also tried replacing the static date for activity_date_deadline with a dynamic filter as follows:

["activity_date_deadline", "=", (context_today() + datetime.timedelta(days=1)).strftime('%%Y-%%m-%%d') ]

When saving this, the change is reverted silently - no error is displayed.

Question:  How should I edit the User-defined Filter to use dynamic filters for User and Date, please?

Avatar
Annuleer

What model are you creating this for? Does the model have a user_id field? Take a look at the Filters defined in the sale.order.list.select view which leverage both UID and context_today() https://github.com/odoo/odoo/blob/14.0/addons/sale/views/sale_views.xml#L728

Hi,

i see [] instead of () in your domain. it should be like this:

domain="[(condition), (condition), (condition), (), ..]"

in your case, it is:

[("customer_rank",">",0),("activity_ids","!=",False),("user_id","=", uid),("activity_date_deadline","=","2021-01-12")]

P.S: If all conditions must have and as an operator, no need to add it in the domain.

Auteur

@Ray Carnes

Thanks for your response. This is being created for the 'Contact' model. The model does have a user_id field - if limiting to a specific named user the filter works - for e.g: ["user_id","ilike","Austen"]

Thank you for the link to the view source that I will test with the the context_today option. If you have any other suggestions for the UID I would certainly appreciate it.

Thank you!

Where are you entering the domain ? Are you using Studio ?

Auteur

@Alessandro Fiorino and @Ibrahim Boudmir

The steps that I follow are as follows:

1. Go to 'Contacts' and create a filter with the following rules:

---Companies,

---Add Custom Filter: Salesperson contains Austen,

---Add Custom Filter: Next Activity Deadline is equal to 13/01/2021

2. Select the drop-down beside 'Favourites' and select 'Save Current Search'

3. Set the name for the search, and select 'Share with all users' then SAVE.

4. Go to 'Settings' (make sure debug is enabled for this step)

5. Select Technical > User Interface > User-defined Filters

6. Select the custom filter created at step 3 and EDIT

The domain is set automatically when creating the filter from the Contacts module. The corresponding code in the code editor is also created by the action of creating the filter.

I am not using Studio for this task.

Let me know if any further information is required - many thanks.

Any solution? I'm struggling with the same problem... 2 years later ...

Beste antwoord

you can achieve dynamic filtering using the following approach:

  1. Create a Custom Filter:

    • First, create a custom filter as you've done.

    • In the filter's domain field, you'll need to set a static condition to ensure the filter is correctly saved. For example:

      ["&", ["customer_rank", ">", 0], ["activity_ids", "!=", False]]
      
  2. Use Context in the Action:

    • Instead of trying to set dynamic values directly in the filter, you can use context variables when defining an action. This action can be associated with a menu item or button.
  3. Set Dynamic Values in the Action:

    • In the action's context, you can set dynamic values for the user and date. Here's an example of how you can define the action:

       id="action_custom_filter" model="ir.actions.server">
          name="name">Custom Filter Action
          name="model_id" ref="model_your_model_name"/>
          name="state">code
          name="code">self.domain = [("customer_rank", ">", 0), ("activity_ids", "!=", False), ("user_id", "=", self.env.user.id), ("activity_date_deadline", "=", fields.Date.today() + timedelta(days=1))] 
      
      

      In this example, self.env.user.id is used to dynamically set the user, and fields.Date.today() + timedelta(days=1) sets the date to tomorrow.

  4. Use the Action in a Menu Item or Button:

    • Finally, you can create a menu item or button and associate it with the action you defined. When users click on this menu item or button, it will apply the dynamic filter based on the context values.


Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
mrt. 15
5967
1
jul. 21
4115
0
dec. 16
5299
0
jul. 25
601
1
mei 25
1375