Merge pull request #331 from foodcoops/feature/configure-upfront-tasks
Configure upfront tasks
This commit is contained in:
commit
cee2ac8f9f
11 changed files with 46 additions and 44 deletions
|
@ -1,8 +1,6 @@
|
|||
class PeriodicTaskGroup < ActiveRecord::Base
|
||||
has_many :tasks, dependent: :destroy
|
||||
|
||||
PeriodDays = 7
|
||||
|
||||
def has_next_task?
|
||||
return false if tasks.empty?
|
||||
return false if tasks.first.due_date.nil?
|
||||
|
@ -11,13 +9,13 @@ class PeriodicTaskGroup < ActiveRecord::Base
|
|||
|
||||
def create_next_task
|
||||
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.due_date = next_task_date
|
||||
next_task.save
|
||||
|
||||
self.next_task_date += PeriodDays
|
||||
self.next_task_date += period_days
|
||||
self.save
|
||||
end
|
||||
|
||||
|
@ -26,4 +24,12 @@ class PeriodicTaskGroup < ActiveRecord::Base
|
|||
t.update_attribute(:periodic_task_group, nil)
|
||||
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
|
||||
|
|
|
@ -36,8 +36,8 @@ class Task < ActiveRecord::Base
|
|||
end
|
||||
|
||||
|
||||
# find all tasks in the next week (or another number of days)
|
||||
def self.next_assigned_tasks_for(user, number = 7)
|
||||
# find all tasks in the period (or another number of days)
|
||||
def self.next_assigned_tasks_for(user, number = FoodsoftConfig[:tasks_period_days].to_i)
|
||||
user.tasks.undone.where(assignments: {accepted: true}).
|
||||
where(["tasks.due_date >= ? AND tasks.due_date <= ?", Time.now, number.days.from_now])
|
||||
end
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
-#= 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_input form, :stop_ordering_under, as: :numeric, input_html: {class: 'input-small'}
|
||||
|
|
|
@ -8,22 +8,7 @@
|
|||
|
||||
- content_for :javascript do
|
||||
: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() {
|
||||
toggleWeeklyTaskFields();
|
||||
$('#workgroup_weekly_task').click(function() {
|
||||
toggleWeeklyTaskFields();
|
||||
});
|
||||
|
||||
$("##{f.object.class.to_s.underscore}_user_tokens").tokenInput("#{users_path(:format => :json)}", {
|
||||
crossDomain: false,
|
||||
prePopulate: $("##{f.object.class.to_s.underscore}_user_tokens").data("pre"),
|
||||
|
|
|
@ -55,14 +55,19 @@ default: &defaults
|
|||
|
||||
# Ordergroups, which have less than 75 apples should not be allowed to make new orders
|
||||
# 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)
|
||||
# use_apple_points: false
|
||||
#use_apple_points: false
|
||||
|
||||
# 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
|
||||
# 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
|
||||
# (recurring dates in ical format; no spaces!)
|
||||
|
|
|
@ -163,7 +163,6 @@ de:
|
|||
workgroup:
|
||||
description: Beschreibung
|
||||
name: Name
|
||||
next_weekly_tasks_number: Für wieviel Wochen im Voraus sollen Aufgaben erstellt werden?
|
||||
role_admin: Administration
|
||||
role_article_meta: Artikeldatenbank
|
||||
role_finance: Finanzen
|
||||
|
@ -185,7 +184,7 @@ de:
|
|||
task:
|
||||
attributes:
|
||||
done:
|
||||
exclusion: erledigte Aufgaben können nicht wöchentlich wiederholt werden
|
||||
exclusion: erledigte Aufgaben können nicht wiederholt werden
|
||||
models:
|
||||
article: Artikel
|
||||
article_category: Artikelkategorie
|
||||
|
@ -1385,12 +1384,9 @@ de:
|
|||
activated: aktiviert
|
||||
apple_limit: Äpfel-Bestellbeschränkung
|
||||
deactivated: deaktiviert
|
||||
no_weekly_job: kein wöchentlicher Job definiert
|
||||
weekly_job: Wöchentlicher Job
|
||||
group_form_fields:
|
||||
search: Suche ...
|
||||
search_user: Nach Nutzerin suchen
|
||||
title: Wöchentliche Jobs
|
||||
user_not_found: Keine Nutzerin gefunden
|
||||
open_orders:
|
||||
no_open_orders: Derzeit gibt es keine laufenden Bestellungen
|
||||
|
|
|
@ -163,7 +163,6 @@ en:
|
|||
workgroup:
|
||||
description: Description
|
||||
name: Name
|
||||
next_weekly_tasks_number: For how many weeks in advance would you like to define tasks?
|
||||
role_admin: Administration
|
||||
role_article_meta: Article database
|
||||
role_finance: Finances
|
||||
|
@ -185,7 +184,7 @@ en:
|
|||
task:
|
||||
attributes:
|
||||
done:
|
||||
exclusion: finished tasks may not be repeated weekly
|
||||
exclusion: finished tasks may not be repeated
|
||||
models:
|
||||
article: Article
|
||||
article_category: Article category
|
||||
|
@ -237,6 +236,8 @@ en:
|
|||
pdf_title: PDF documents
|
||||
tab_messages:
|
||||
emails_title: Sending email
|
||||
tab_tasks:
|
||||
periodic_title: Periodic tasks
|
||||
tabs:
|
||||
title: Configuration
|
||||
update:
|
||||
|
@ -472,6 +473,8 @@ en:
|
|||
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.
|
||||
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.
|
||||
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.
|
||||
|
@ -512,6 +515,8 @@ en:
|
|||
pdf_page_size: Page size
|
||||
price_markup: Foodcoop margin
|
||||
stop_ordering_under: Minimum apple points
|
||||
tasks_period_days: Period
|
||||
tasks_upfront_days: Create upfront
|
||||
tax_default: Default VAT
|
||||
time_zone: Time zone
|
||||
tolerance_is_costly: Tolerance is costly
|
||||
|
@ -1408,12 +1413,9 @@ en:
|
|||
activated: activated
|
||||
apple_limit: Apple points order limit
|
||||
deactivated: deactivated
|
||||
no_weekly_job: No weekly job defined
|
||||
weekly_job: Weekly job
|
||||
group_form_fields:
|
||||
search: Search ...
|
||||
search_user: Search user
|
||||
title: Weekly jobs
|
||||
user_not_found: No user found
|
||||
open_orders:
|
||||
no_open_orders: There are no current orders
|
||||
|
|
|
@ -163,7 +163,6 @@ fr:
|
|||
workgroup:
|
||||
description: Description
|
||||
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_article_meta: Base de données des produits
|
||||
role_finance: Trésorerie
|
||||
|
@ -185,7 +184,7 @@ fr:
|
|||
task:
|
||||
attributes:
|
||||
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:
|
||||
article: Article
|
||||
article_category: Catégorie
|
||||
|
@ -1398,12 +1397,9 @@ fr:
|
|||
activated: activé
|
||||
apple_limit: Minimum de glands
|
||||
deactivated: désactivé
|
||||
no_weekly_job: aucun boulot hebdomadaire n'a été défini
|
||||
weekly_job: Boulot hebdomadaire
|
||||
group_form_fields:
|
||||
search: Recherche...
|
||||
search_user: Rechercher par utilisatrice
|
||||
title: Boulots hebdomadaires
|
||||
user_not_found: Aucun-e membre ne correspond à ce nom
|
||||
open_orders:
|
||||
no_open_orders: Il n'y a aucune commande en cours en ce moment
|
||||
|
|
|
@ -163,7 +163,6 @@ nl:
|
|||
workgroup:
|
||||
description: Omschrijving
|
||||
name: Naam
|
||||
next_weekly_tasks_number: Hoeveel weken vooruit moet de taak zichtbaar zijn?
|
||||
role_admin: Beheer
|
||||
role_article_meta: Artikelen
|
||||
role_finance: Financiën
|
||||
|
@ -1391,12 +1390,9 @@ nl:
|
|||
activated: actief
|
||||
apple_limit: Appelpunten bestellingslimiet
|
||||
deactivated: inactief
|
||||
no_weekly_job: geen wekelijkse taak ingesteld
|
||||
weekly_job: wekelijkse taak
|
||||
group_form_fields:
|
||||
search: Zoeken ...
|
||||
search_user: Gebruiker zoeken
|
||||
title: Wekelijkse taken
|
||||
user_not_found: Geen gebruiker gevonden
|
||||
open_orders:
|
||||
no_open_orders: Er zijn momenteel geen lopende bestellingen.
|
||||
|
|
|
@ -226,6 +226,8 @@ class FoodsoftConfig
|
|||
currency_space: true,
|
||||
foodsoft_url: 'https://github.com/foodcoops/foodsoft',
|
||||
contact: {}, # avoid errors when undefined
|
||||
tasks_period_days: 7,
|
||||
tasks_upfront_days: 49,
|
||||
# The following keys cannot, by default, be set by foodcoops themselves.
|
||||
protected: {
|
||||
multi_coop_install: true,
|
||||
|
|
|
@ -40,7 +40,9 @@ namespace :foodsoft do
|
|||
task :create_upcoming_periodic_tasks => :environment do
|
||||
for tg in PeriodicTaskGroup.all
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue