Hello,
is it possible to use a domain filter in a record rule that works with a datetime field to filter all entries from "today - 4 weeks" to "today"?
Greetings
RSK
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hello,
is it possible to use a domain filter in a record rule that works with a datetime field to filter all entries from "today - 4 weeks" to "today"?
Greetings
RSK
I don't think you can do this in a Record Rule, but you could add a filter in an Extension Search View and use that in the Windows Action.
Something like this:
<?xml version="1.0"?>Then this new filter needs to be set as context in the Windows Action:
<xpath expr="//filter[@name='my_sale_orders_filter']" position="after">
<filter string="Last 4 weeks" name="four_weeks"
domain="[('date_order','>=',(context_today() +
relativedelta(weeks=-4, weekday=0)).strftime('%Y-%m-%d'))]"
/>
</xpath>
{'search_default_four_weeks': 1}]But users can remove the filter.
=====
Another idea is to create a new boolean field on Sales Orders, and run a scheduled job every day to set this ON when an order is 4 weeks old. Then you can create a Record Rule to limit access to older orders.
This is an example of the Python code, but you'd need to create a new module to run it (Scheduled Actions can't run Server Actions):
for rec in records:
rec['x_recent_order'] = False
if rec.date_order > (datetime.datetime.today() - datetime.timedelta(weeks=4)):
rec['x_recent_order'] = True
x_recent_order is the new boolean field. Hope this helps!
Will this filter be applied and forced for every user?
No, it will be a filter that users can select.
Then it's not what I'm looking for. Thanks anyway
Yes, filters won't do that. I updated my answer and added another idea.
Sounds like the best way for me. I already got the record rule and the boolean field going. This is working as expected, now I just need to get the scheduled task working. Do you have the python code example for that?
I'm not really a Python programmer, but I have added some code that I tested in a Server Action. Should be straightforward for a developer to add this to a Scheduled Action.
Refer Odoo developer documentation https://www.odoo.com/documentation/13.0/reference/security.html
a domain used to check whether a given record matches the rule (and is accessible) or does not (and is not accessible). The domain is evaluated with two variables in context: user
is the current user’s record and time
is the time module
You can use only two predefined variables in the record rule.
user
It's the browsable object of res.users model.
time
is the time module which provides various time-related functions
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
2
Oct 22
|
9950 | ||
|
3
Jan 24
|
624 | ||
|
1
Dec 23
|
2047 | ||
|
2
May 21
|
1568 | ||
|
0
Mar 15
|
2967 |