Issue: instead of updating all Accounts in core.tasks.update_account_status -- updating only Accounts with expiration dates this month or earlier.
Possible to make this even more narrow -- see https://www.evernote.com/shard/s1/sh/35adfc05-46cc-41b7-865e-8a0edb652fd0/a18917c04c0262cd624208b7a071ec52pull/1/head
parent
37ce78fda2
commit
4fc449dad5
|
@ -13,6 +13,7 @@ django imports
|
|||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.mail import send_mail
|
||||
from django.db.models import Q
|
||||
from notification.engine import send_all
|
||||
from notification import models as notification
|
||||
|
||||
|
@ -100,11 +101,20 @@ def update_active_campaign_status():
|
|||
|
||||
#task to update the status of accounts
|
||||
@task
|
||||
def update_account_status():
|
||||
def update_account_status(all_accounts=True):
|
||||
"""update the status of all Accounts"""
|
||||
errors = []
|
||||
|
||||
for account in Account.objects.all():
|
||||
if all_accounts:
|
||||
accounts_to_calc = Account.objects.all()
|
||||
else:
|
||||
# active accounts with expiration dates from this month earlier
|
||||
today = date_today()
|
||||
year = today.year
|
||||
month = today.month
|
||||
accounts_to_calc = Account.objects.filter(Q(date_deactivated__isnull=True)).filter((Q(card_exp_year__lt=year) | Q(card_exp_year=year, card_exp_month__lte = month)))
|
||||
|
||||
for account in accounts_to_calc:
|
||||
try:
|
||||
account.status = account.calculated_status()
|
||||
account.save()
|
||||
|
|
|
@ -27,6 +27,19 @@
|
|||
"metadata": {},
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# use the localdatetime?\n",
|
||||
"\n",
|
||||
"from regluit.utils import localdatetime\n",
|
||||
"localdatetime.date_today()"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 2,
|
||||
|
@ -42,14 +55,21 @@
|
|||
"from regluit.payment.models import Account\n",
|
||||
"from django.db.models import Q\n",
|
||||
"import datetime\n",
|
||||
"from dateutil.relativedelta import relativedelta\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# set the month/year for comparison\n",
|
||||
"\n",
|
||||
"#\n",
|
||||
"# # http://stackoverflow.com/a/15155212/7782\n",
|
||||
"today = datetime.date.today()\n",
|
||||
"year = today.year\n",
|
||||
"month = today.month\n",
|
||||
"\n",
|
||||
"date_before_month = today + relativedelta(months=-1)\n",
|
||||
"year_last_month = date_before_month.year\n",
|
||||
"month_last_month = date_before_month.month\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"#year = 2013\n",
|
||||
"#month = 2\n",
|
||||
"\n",
|
||||
|
@ -83,6 +103,67 @@
|
|||
"metadata": {},
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# looking at filtering Accounts that might expire\n",
|
||||
"\n",
|
||||
"# if the the month of the expiration date == next month or earlier \n",
|
||||
"# accounts with expiration of this month and last month -- and to be more expansive filter: expiration with this month or before\n",
|
||||
"# also Account.objects.filter(Q(date_deactivated__isnull=True))\n",
|
||||
"# \n",
|
||||
"# accounts_expired = active_accounts.filter((Q(card_exp_year__lt=year) | Q(card_exp_year=year, card_exp_month__lt = month)))\n",
|
||||
"\n",
|
||||
"accounts_to_consider_expansive = Account.objects.filter(Q(date_deactivated__isnull=True)).filter((Q(card_exp_year__lt=year) | Q(card_exp_year=year, card_exp_month__lte = month)))\n",
|
||||
"\n",
|
||||
"# this month or last last monthj\n",
|
||||
"accounts_to_consider_narrow = Account.objects.filter(Q(date_deactivated__isnull=True)).filter(Q(card_exp_year=year, card_exp_month = month) | Q(card_exp_year=year_last_month, card_exp_month = month_last_month))\n",
|
||||
"\n",
|
||||
"for account in accounts_to_consider_narrow:\n",
|
||||
" print (account.user, account.card_exp_month, account.card_exp_year) "
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"from regluit.utils.localdatetime import date_today\n",
|
||||
"\n",
|
||||
"today = date_today()\n",
|
||||
"year = today.year\n",
|
||||
"month = today.month\n",
|
||||
"accounts_to_calc = Account.objects.filter(Q(date_deactivated__isnull=True)).filter((Q(card_exp_year__lt=year) | Q(card_exp_year=year, card_exp_month__lte = month)))\n",
|
||||
"accounts_to_calc"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"from regluit.core import tasks\n",
|
||||
"k = tasks.update_account_status.apply(args=[False])"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"k.get()"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
|
|
Loading…
Reference in New Issue