You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
967 B
32 lines
967 B
# -*- coding: utf-8 -*-
|
|
from __future__ import absolute_import
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from celery import shared_task
|
|
|
|
from project.commons.utils import mail_exception
|
|
|
|
from project.customer.models import License, UserProfile
|
|
from project.customer.utils import check_one_profile
|
|
from project.customer import consts
|
|
|
|
|
|
@shared_task
|
|
def check_license():
|
|
profiles = UserProfile.objects.all()
|
|
now_ = datetime.today()
|
|
|
|
licenses = License.objects.filter(order_date__lte = now_ - timedelta(days=consts.ORDER_PAY_DAYS),
|
|
order_status=consts.ORDER_UNPAID, deleted=False)
|
|
|
|
# çàìîðîçèòü íåîïëà÷åííûå â ñðîê ñ÷åòà
|
|
licenses.update(order_status=consts.ORDER_SUSPENDED, suspend_date=_now.date())
|
|
|
|
for profile in profiles:
|
|
try:
|
|
check_one_profile(profile, License, now_)
|
|
except Exception as e:
|
|
mail_exception(u'customer: check_license error', u'Profile id=%d.' % profile.pk, e)
|
|
|
|
return None
|
|
|