Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odgovori
1454 Prikazi

Hello, I tried to buid a filter on Odoo V15 to sort out the number of order delivered in the 5 days after ordering for our ISO9001 statistics. The goal is effective_date <= order_date + 5 days. All I tried cause domain fail. I'm just a user and new in Python so I assume it's just a simple problem for a lot of you. Thanks in advance for your help. Philippe.

Avatar
Opusti
Best Answer

Actually, it is not an easy problem as far as I know. 
Let's say this, domain = (operand_a, operator, operand_b). operand_a can be a field name of the model but the operand_b can only be a static value in the case of search filter domain. But your problem demands operand_b to be a model field.

Now, if you explain a little bit about where you want this filter to take effect, I might be able to assist you.

moreover, you can do this by implementing a button to filter this, you may want to follow these steps,
1. firstly create a wizard and add it to a menu and this wizard should include a button that does the filtering and returns a tree view.
2. in the method of the button, get all the sale orders. sale_orders = self.env['sale.order'].search([]).
3. filter out the id of such orders you desire. ex.: filtered_order_ids = sale_order.filter(lambda od: od.effective_date <= od.date_order+5).mapped('id')
4. then return an action that has the tree view and append the domain in the view. ex.: `
action = self.env.ref('your_module.your_action').read()[0]
action['domain'] = [('id', 'in', filtered_order_ids)]
return action`

hope this helps


Avatar
Opusti
Avtor Best Answer

Hi Cybrisys, Thanks for your answer, already tried without success, perhaps just a formulation problem :  [('effective_date','<=',(order_date + timedelta(days=5)))]

Regards

Avatar
Opusti
Best Answer

Hi,

Try like following.

effective_date <= order_date + timedelta(days=5)

Regards

Avatar
Opusti