Advertisement
mariomolinos

Update Booking Filters

Aug 8th, 2022 (edited)
1,588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. today = datetime.datetime.now()
  2. context_today = datetime.datetime.now().date
  3. today_domain = ['&',("x_studio_date", ">=", (context_today().strftime('%Y-%m-%d'))), ("x_studio_date", "<=", (context_today().strftime('%Y-%m-%d')))]
  4. bookings = 'x_bookings'
  5. filter_delete = env['ir.filters'].search([("model_id","=","x_bookings")])
  6.  
  7. for f in filter_delete:
  8.   f.unlink()
  9.  
  10. weekdays = {
  11.   0 : "Monday",
  12.   1 : "Tuesday",
  13.   2 : "Wednesday",
  14.   3 : "Thursday",
  15.   4 : "Friday",
  16.   5 : "Saturday",
  17.   6 : "Sunday"
  18.   }
  19.  
  20. for n in range(0,8):
  21.     day = today + datetime.timedelta(days=n)
  22.     weekday = day.weekday() #0 - 6
  23.     day_num = day.strftime("%y-%m-%d")
  24.     day_str = str(day_num)
  25.     domain = ['&',("x_studio_date", ">=", ((context_today()+datetime.timedelta(days=n)).strftime('%Y-%m-%d'))), ("x_studio_date", "<=", ((context_today()+datetime.timedelta(days=n)).strftime('%Y-%m-%d')))]
  26.    
  27.     if weekday not in (5,6):
  28.       weekday_name = weekdays[weekday]
  29.       date = day_str + " " + str(weekday_name)
  30.       if n == 0:
  31.         date = date + " - Today"
  32.       domain_weekday = str(domain)
  33.        
  34.       filters = env['ir.filters'].create({'name': date, 'model_id': 'x_bookings', 'domain': domain_weekday})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement