Project

General

Profile

Patch #20121 » redmine-reminder_respect_nonworking_days-v2.diff

Alexander Stehlik, 2015-06-17 19:01

View differences:

app/models/mailer.rb
97 97
    end
98 98
  end
99 99

  
100
  def reminder(user, issues, days)
100
  def reminder(user, issues, days, respect_working_days)
101 101
    set_language_if_valid user.language
102 102
    @issues = issues
103 103
    @days = days
104
    @respect_working_days = respect_working_days
104 105
    @issues_url = url_for(:controller => 'issues', :action => 'index',
105 106
                                :set_filter => 1, :assigned_to_id => user.id,
106 107
                                :sort => 'due_date:asc')
......
324 325

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

  
336
    extend Redmine::Utils::DateCalculation
337

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

  
347
    days_requested = days
348
    if options[:respect_working_days]
349
      working_day_count = working_days(Date.today, (days + 7).day.from_now.to_date)
350
      days = days + (days + 7 - working_day_count)
351
    end
352

  
342 353
    scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" +
343 354
      " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" +
344 355
      " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date
......
359 370
    end
360 371

  
361 372
    issues_by_assignee.each do |assignee, issues|
362
      reminder(assignee, issues, days).deliver if assignee.is_a?(User) && assignee.active?
373
      reminder(assignee, issues, days_requested, options[:respect_working_days]).deliver if assignee.is_a?(User) && assignee.active?
363 374
    end
364 375
  end
365 376

  
app/views/mailer/reminder.html.erb
1
<p><%= l(:mail_body_reminder, :count => @issues.size, :days => @days) %></p>
1
<p><%= l(@respect_working_days ? :mail_body_reminder_working_days : :mail_body_reminder, :count => @issues.size, :days => @days) %></p>
2 2

  
3 3
<ul>
4 4
<% @issues.each do |issue| -%>
app/views/mailer/reminder.text.erb
1
<%= l(:mail_body_reminder, :count => @issues.size, :days => @days) %>:
1
<%= l(@respect_working_days ? :mail_body_reminder_working_days : :mail_body_reminder, :count => @issues.size, :days => @days) %>
2 2

  
3 3
<% @issues.each do |issue| -%>
4 4
* <%= "#{issue.project} - #{issue.tracker} ##{issue.id}: #{issue.subject}" %>
config/locales/de.yml
846 846
  mail_body_lost_password: 'Benutzen Sie den folgenden Link, um Ihr Kennwort zu ändern:'
847 847
  mail_body_register: 'Um Ihr Konto zu aktivieren, benutzen Sie folgenden Link:'
848 848
  mail_body_reminder: "%{count} Tickets, die Ihnen zugewiesen sind, müssen in den nächsten %{days} Tagen abgegeben werden:"
849
  mail_body_reminder_working_days: "%{count} Tickets, die Ihnen zugewiesen sind, müssen in den nächsten %{days} Arbeitstagen abgegeben werden:"
849 850
  mail_body_wiki_content_added: "Die Wiki-Seite '%{id}' wurde von %{author} hinzugefügt."
850 851
  mail_body_wiki_content_updated: "Die Wiki-Seite '%{id}' wurde von %{author} aktualisiert."
851 852
  mail_subject_account_activation_request: "Antrag auf %{value} Kontoaktivierung"
config/locales/en-GB.yml
209 209
  mail_body_account_activation_request: "A new user (%{value}) has registered. The account is pending your approval:"
210 210
  mail_subject_reminder: "%{count} issue(s) due in the next %{days} days"
211 211
  mail_body_reminder: "%{count} issue(s) that are assigned to you are due in the next %{days} days:"
212
  mail_body_reminder_working_days: "%{count} issue(s) that are assigned to you are due in the next %{days} working days:"
212 213
  mail_subject_wiki_content_added: "'%{id}' wiki page has been added"
213 214
  mail_body_wiki_content_added: "The '%{id}' wiki page has been added by %{author}."
214 215
  mail_subject_wiki_content_updated: "'%{id}' wiki page has been updated"
config/locales/en.yml
216 216
  mail_body_account_activation_request: "A new user (%{value}) has registered. The account is pending your approval:"
217 217
  mail_subject_reminder: "%{count} issue(s) due in the next %{days} days"
218 218
  mail_body_reminder: "%{count} issue(s) that are assigned to you are due in the next %{days} days:"
219
  mail_body_reminder_working_days: "%{count} issue(s) that are assigned to you are due in the next %{days} working days:"
219 220
  mail_subject_wiki_content_added: "'%{id}' wiki page has been added"
220 221
  mail_body_wiki_content_added: "The '%{id}' wiki page has been added by %{author}."
221 222
  mail_subject_wiki_content_updated: "'%{id}' wiki page has been updated"
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_working_days] = !!ENV['respect_working_days']
40 41

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