summaryrefslogtreecommitdiff
path: root/users/app/models
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-12-30 16:22:38 -0800
committerjessib <jessib@riseup.net>2013-12-30 16:22:38 -0800
commit4dae5eaa1bdb211d9d3ff29d5a9e9a86424e9748 (patch)
treea24c9e490a66ff9144386b8bd4ed2bb7a62ec197 /users/app/models
parent396165d867f2009be1b1071d3c001009adf628ee (diff)
Fixes to initial go at job to send one month warnings.
Diffstat (limited to 'users/app/models')
-rw-r--r--users/app/models/user.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index d9b03ec..30b9ee7 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -15,6 +15,7 @@ class User < CouchRest::Model::Base
property :message_ids_to_see, [String]
property :message_ids_seen, [String]
+ property :one_month_warning_sent, TrueClass
before_save :update_effective_service_level
@@ -135,7 +136,10 @@ class User < CouchRest::Model::Base
ServiceLevel.new({id: code})
end
- def one_month_warning_to_pay
+
+ def self.send_one_month_warnings # class not instance method
+
+=begin
# get all users who are not customers with active subscription and have existed for exactly a month (take account of months having difft amount of days. Maybe just those who signed up 30 days ago?)
#users_to_warn = User.find_by_created_at(Time.now-1.month).all #NO, this will require time to be right
#users_1_month_old = User.by_created_at.startkey(Time.now-1.month-1.day).endkey(Time.now-1.month).al
@@ -161,6 +165,23 @@ class User < CouchRest::Model::Base
user_message.save
end
end
+=end
+
+ #to determine warnings to send, need to get all users where one_month_warning_sent is not set, and where it was created greater than or equal to 1 month ago. this will likely be custom js view/design
+ users_to_warn = User.by_created_at_and_one_month_warning_not_sent.endkey(Time.now-1.month)
+ users_to_warn.each do |user|
+ if !@message
+ # create a message for today's date
+ # only want to create once, and only if it will be used.
+ @message = Message.new(:text => t(:payment_one_month_warning, :date_in_one_month => (Time.now+1.month).strftime("%Y-%d-%m")))
+ @message.save
+ end
+
+ user.message_ids_to_see << @message.id
+ user.one_month_warning_sent = true
+ user.save #??
+ end
+
end
protected