Project

General

Profile

Patch #20121 » redmine-reminder_respect_nonworking_days.diff

Alexander Stehlik, 2015-06-17 18:24

View differences:

app/models/mailer.rb
324 324

  
325 325
  # Sends reminders to issue assignees
326 326
  # Available options:
327
  # * :days     => how many days in the future to remind about (defaults to 7)
328
  # * :tracker  => id of tracker for filtering issues (defaults to all trackers)
329
  # * :project  => id or identifier of project to process (defaults to all projects)
330
  # * :users    => array of user/group ids who should be reminded
331
  # * :version  => name of target version for filtering issues (defaults to none)
327
  # * :days                     => how many days in the future to remind about (defaults to 7)
328
  # * :tracker                  => id of tracker for filtering issues (defaults to all trackers)
329
  # * :project                  => id or identifier of project to process (defaults to all projects)
330
  # * :users                    => array of user/group ids who should be reminded
331
  # * :version                  => name of target version for filtering issues (defaults to none)
332
  # * :respect_nonworking_days  => if true the non working days setting will be used to calculate the date difference
332 333
  def self.reminders(options={})
334

  
335
    extend Redmine::Utils::DateCalculation
336

  
333 337
    days = options[:days] || 7
334 338
    project = options[:project] ? Project.find(options[:project]) : nil
335 339
    tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
......
339 343
    end
340 344
    user_ids = options[:users]
341 345

  
346
    if options[:respect_nonworking_days]
347
      working_day_count = working_days(Date.today, days.day.from_now.to_date)
348
      days = days + (days - working_day_count)
349
    end
350

  
342 351
    scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" +
343 352
      " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" +
344 353
      " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date
lib/tasks/reminder.rake
37 37
    options[:tracker] = ENV['tracker'].to_i if ENV['tracker']
38 38
    options[:users] = (ENV['users'] || '').split(',').each(&:strip!)
39 39
    options[:version] = ENV['version'] if ENV['version'] 
40
    options[:respect_nonworking_days] = !!ENV['respect_nonworking_days']
40 41

  
41 42
    Mailer.with_synched_deliveries do
42 43
      Mailer.reminders(options)
(1-1/2)