Merge pull request #331 from foodcoops/feature/configure-upfront-tasks

Configure upfront tasks
This commit is contained in:
wvengen 2014-12-06 14:35:22 +01:00
commit cee2ac8f9f
11 changed files with 46 additions and 44 deletions

View file

@ -1,8 +1,6 @@
class PeriodicTaskGroup < ActiveRecord::Base class PeriodicTaskGroup < ActiveRecord::Base
has_many :tasks, dependent: :destroy has_many :tasks, dependent: :destroy
PeriodDays = 7
def has_next_task? def has_next_task?
return false if tasks.empty? return false if tasks.empty?
return false if tasks.first.due_date.nil? return false if tasks.first.due_date.nil?
@ -11,13 +9,13 @@ class PeriodicTaskGroup < ActiveRecord::Base
def create_next_task def create_next_task
template_task = tasks.first template_task = tasks.first
self.next_task_date ||= template_task.due_date + PeriodDays self.next_task_date ||= template_task.due_date + period_days
next_task = template_task.dup next_task = template_task.dup
next_task.due_date = next_task_date next_task.due_date = next_task_date
next_task.save next_task.save
self.next_task_date += PeriodDays self.next_task_date += period_days
self.save self.save
end end
@ -26,4 +24,12 @@ class PeriodicTaskGroup < ActiveRecord::Base
t.update_attribute(:periodic_task_group, nil) t.update_attribute(:periodic_task_group, nil)
end end
end end
protected
# @return [Number] Number of days between two periodic tasks
def period_days
# minimum of one to avoid inifite loop when value is invalid
[FoodsoftConfig[:tasks_period_days].to_i, 1].max
end
end end

View file

@ -36,8 +36,8 @@ class Task < ActiveRecord::Base
end end
# find all tasks in the next week (or another number of days) # find all tasks in the period (or another number of days)
def self.next_assigned_tasks_for(user, number = 7) def self.next_assigned_tasks_for(user, number = FoodsoftConfig[:tasks_period_days].to_i)
user.tasks.undone.where(assignments: {accepted: true}). user.tasks.undone.where(assignments: {accepted: true}).
where(["tasks.due_date >= ? AND tasks.due_date <= ?", Time.now, number.days.from_now]) where(["tasks.due_date >= ? AND tasks.due_date <= ?", Time.now, number.days.from_now])
end end

View file

@ -1,3 +1,15 @@
-#= config_use_heading form, :use_tasks do -#= config_use_heading form, :use_tasks do
%fieldset
%label
%h4= t '.periodic_title'
= config_input form, :tasks_period_days do
.input-append
= config_input_field form, :tasks_period_days, as: :numeric, class: 'input-mini'
%span.add-on days
= config_input form, :tasks_upfront_days do
.input-append
= config_input_field form, :tasks_upfront_days, as: :numeric, class: 'input-mini'
%span.add-on days
= config_use_heading form, :use_apple_points do = config_use_heading form, :use_apple_points do
= config_input form, :stop_ordering_under, as: :numeric, input_html: {class: 'input-small'} = config_input form, :stop_ordering_under, as: :numeric, input_html: {class: 'input-small'}

View file

@ -8,22 +8,7 @@
- content_for :javascript do - content_for :javascript do
:javascript :javascript
function toggleWeeklyTaskFields() {
if ($('#workgroup_weekly_task').is(':checked')) {
$('#weekly_task_fields .control-group').show();
$('#weekly_task_fields input').removeAttr('disabled');
} else {
$('#weekly_task_fields .control-group').hide();
$('#weekly_task_fields input').attr('disabled', 'disabled');
}
}
$(function() { $(function() {
toggleWeeklyTaskFields();
$('#workgroup_weekly_task').click(function() {
toggleWeeklyTaskFields();
});
$("##{f.object.class.to_s.underscore}_user_tokens").tokenInput("#{users_path(:format => :json)}", { $("##{f.object.class.to_s.underscore}_user_tokens").tokenInput("#{users_path(:format => :json)}", {
crossDomain: false, crossDomain: false,
prePopulate: $("##{f.object.class.to_s.underscore}_user_tokens").data("pre"), prePopulate: $("##{f.object.class.to_s.underscore}_user_tokens").data("pre"),

View file

@ -55,14 +55,19 @@ default: &defaults
# Ordergroups, which have less than 75 apples should not be allowed to make new orders # Ordergroups, which have less than 75 apples should not be allowed to make new orders
# Comment out this option to activate this restriction # Comment out this option to activate this restriction
# stop_ordering_under: 75 #stop_ordering_under: 75
# Comment out to completely hide apple points (be sure to comment stop_ordering_under) # Comment out to completely hide apple points (be sure to comment stop_ordering_under)
# use_apple_points: false #use_apple_points: false
# ordergroups can only order when their balance is higher than or equal to this # ordergroups can only order when their balance is higher than or equal to this
# not fully enforced right now, since the check is only client-side # not fully enforced right now, since the check is only client-side
# minimum_balance: 0 #minimum_balance: 0
# how many days there are between two periodic tasks
#tasks_period_days: 7
# how many days upfront periodic tasks are created
#tasks_upfront_days: 49
# default order schedule, used to provide initial dates for new orders # default order schedule, used to provide initial dates for new orders
# (recurring dates in ical format; no spaces!) # (recurring dates in ical format; no spaces!)

View file

@ -163,7 +163,6 @@ de:
workgroup: workgroup:
description: Beschreibung description: Beschreibung
name: Name name: Name
next_weekly_tasks_number: Für wieviel Wochen im Voraus sollen Aufgaben erstellt werden?
role_admin: Administration role_admin: Administration
role_article_meta: Artikeldatenbank role_article_meta: Artikeldatenbank
role_finance: Finanzen role_finance: Finanzen
@ -185,7 +184,7 @@ de:
task: task:
attributes: attributes:
done: done:
exclusion: erledigte Aufgaben können nicht wöchentlich wiederholt werden exclusion: erledigte Aufgaben können nicht wiederholt werden
models: models:
article: Artikel article: Artikel
article_category: Artikelkategorie article_category: Artikelkategorie
@ -1385,12 +1384,9 @@ de:
activated: aktiviert activated: aktiviert
apple_limit: Äpfel-Bestellbeschränkung apple_limit: Äpfel-Bestellbeschränkung
deactivated: deaktiviert deactivated: deaktiviert
no_weekly_job: kein wöchentlicher Job definiert
weekly_job: Wöchentlicher Job
group_form_fields: group_form_fields:
search: Suche ... search: Suche ...
search_user: Nach Nutzerin suchen search_user: Nach Nutzerin suchen
title: Wöchentliche Jobs
user_not_found: Keine Nutzerin gefunden user_not_found: Keine Nutzerin gefunden
open_orders: open_orders:
no_open_orders: Derzeit gibt es keine laufenden Bestellungen no_open_orders: Derzeit gibt es keine laufenden Bestellungen

View file

@ -163,7 +163,6 @@ en:
workgroup: workgroup:
description: Description description: Description
name: Name name: Name
next_weekly_tasks_number: For how many weeks in advance would you like to define tasks?
role_admin: Administration role_admin: Administration
role_article_meta: Article database role_article_meta: Article database
role_finance: Finances role_finance: Finances
@ -185,7 +184,7 @@ en:
task: task:
attributes: attributes:
done: done:
exclusion: finished tasks may not be repeated weekly exclusion: finished tasks may not be repeated
models: models:
article: Article article: Article
article_category: Article category article_category: Article category
@ -237,6 +236,8 @@ en:
pdf_title: PDF documents pdf_title: PDF documents
tab_messages: tab_messages:
emails_title: Sending email emails_title: Sending email
tab_tasks:
periodic_title: Periodic tasks
tabs: tabs:
title: Configuration title: Configuration
update: update:
@ -472,6 +473,8 @@ en:
price_markup: Percentage that is added to the gross price for foodcoop members. price_markup: Percentage that is added to the gross price for foodcoop members.
stop_ordering_under: Members can only order when they have at least this many apple points. stop_ordering_under: Members can only order when they have at least this many apple points.
tax_default: Default VAT percentage for new articles. tax_default: Default VAT percentage for new articles.
tasks_period_days: Number of days between two periodic tasks (default 7, which is a week).
tasks_upfront_days: For how many days in advance you would like to schedule periodic tasks.
tolerance_is_costly: Order as much of the member tolerance as possible (compared to only as much needed to fill the last box). Enabling this also includes the tolerance in the total price of the open member order. tolerance_is_costly: Order as much of the member tolerance as possible (compared to only as much needed to fill the last box). Enabling this also includes the tolerance in the total price of the open member order.
use_apple_points: When the apple point system is enabled, members are required to do some tasks to be able to keep ordering. use_apple_points: When the apple point system is enabled, members are required to do some tasks to be able to keep ordering.
use_messages: Allow members to communicate with each other within Foodsoft. use_messages: Allow members to communicate with each other within Foodsoft.
@ -512,6 +515,8 @@ en:
pdf_page_size: Page size pdf_page_size: Page size
price_markup: Foodcoop margin price_markup: Foodcoop margin
stop_ordering_under: Minimum apple points stop_ordering_under: Minimum apple points
tasks_period_days: Period
tasks_upfront_days: Create upfront
tax_default: Default VAT tax_default: Default VAT
time_zone: Time zone time_zone: Time zone
tolerance_is_costly: Tolerance is costly tolerance_is_costly: Tolerance is costly
@ -1408,12 +1413,9 @@ en:
activated: activated activated: activated
apple_limit: Apple points order limit apple_limit: Apple points order limit
deactivated: deactivated deactivated: deactivated
no_weekly_job: No weekly job defined
weekly_job: Weekly job
group_form_fields: group_form_fields:
search: Search ... search: Search ...
search_user: Search user search_user: Search user
title: Weekly jobs
user_not_found: No user found user_not_found: No user found
open_orders: open_orders:
no_open_orders: There are no current orders no_open_orders: There are no current orders

View file

@ -163,7 +163,6 @@ fr:
workgroup: workgroup:
description: Description description: Description
name: Nom name: Nom
next_weekly_tasks_number: Combien de temps en avance les boulots doivent ils être annoncés sur le site?
role_admin: Administration role_admin: Administration
role_article_meta: Base de données des produits role_article_meta: Base de données des produits
role_finance: Trésorerie role_finance: Trésorerie
@ -185,7 +184,7 @@ fr:
task: task:
attributes: attributes:
done: done:
exclusion: répétition hebdomadaire invalide pour un boulot déjà effectué exclusion: répétition invalide pour un boulot déjà effectué
models: models:
article: Article article: Article
article_category: Catégorie article_category: Catégorie
@ -1398,12 +1397,9 @@ fr:
activated: activé activated: activé
apple_limit: Minimum de glands apple_limit: Minimum de glands
deactivated: désactivé deactivated: désactivé
no_weekly_job: aucun boulot hebdomadaire n'a été défini
weekly_job: Boulot hebdomadaire
group_form_fields: group_form_fields:
search: Recherche... search: Recherche...
search_user: Rechercher par utilisatrice search_user: Rechercher par utilisatrice
title: Boulots hebdomadaires
user_not_found: Aucun-e membre ne correspond à ce nom user_not_found: Aucun-e membre ne correspond à ce nom
open_orders: open_orders:
no_open_orders: Il n'y a aucune commande en cours en ce moment no_open_orders: Il n'y a aucune commande en cours en ce moment

View file

@ -163,7 +163,6 @@ nl:
workgroup: workgroup:
description: Omschrijving description: Omschrijving
name: Naam name: Naam
next_weekly_tasks_number: Hoeveel weken vooruit moet de taak zichtbaar zijn?
role_admin: Beheer role_admin: Beheer
role_article_meta: Artikelen role_article_meta: Artikelen
role_finance: Financiën role_finance: Financiën
@ -1391,12 +1390,9 @@ nl:
activated: actief activated: actief
apple_limit: Appelpunten bestellingslimiet apple_limit: Appelpunten bestellingslimiet
deactivated: inactief deactivated: inactief
no_weekly_job: geen wekelijkse taak ingesteld
weekly_job: wekelijkse taak
group_form_fields: group_form_fields:
search: Zoeken ... search: Zoeken ...
search_user: Gebruiker zoeken search_user: Gebruiker zoeken
title: Wekelijkse taken
user_not_found: Geen gebruiker gevonden user_not_found: Geen gebruiker gevonden
open_orders: open_orders:
no_open_orders: Er zijn momenteel geen lopende bestellingen. no_open_orders: Er zijn momenteel geen lopende bestellingen.

View file

@ -226,6 +226,8 @@ class FoodsoftConfig
currency_space: true, currency_space: true,
foodsoft_url: 'https://github.com/foodcoops/foodsoft', foodsoft_url: 'https://github.com/foodcoops/foodsoft',
contact: {}, # avoid errors when undefined contact: {}, # avoid errors when undefined
tasks_period_days: 7,
tasks_upfront_days: 49,
# The following keys cannot, by default, be set by foodcoops themselves. # The following keys cannot, by default, be set by foodcoops themselves.
protected: { protected: {
multi_coop_install: true, multi_coop_install: true,

View file

@ -40,7 +40,9 @@ namespace :foodsoft do
task :create_upcoming_periodic_tasks => :environment do task :create_upcoming_periodic_tasks => :environment do
for tg in PeriodicTaskGroup.all for tg in PeriodicTaskGroup.all
if tg.has_next_task? if tg.has_next_task?
while tg.next_task_date.nil? or tg.next_task_date < Date.today + 50 create_until = Date.today + FoodsoftConfig[:tasks_upfront_days].to_i + 1
rake_say "creating until #{create_until}"
while tg.next_task_date.nil? or tg.next_task_date < create_until
tg.create_next_task tg.create_next_task
end end
end end