def get_membership_count(self, days):
        from tendenci.apps.memberships.models import MembershipDefault

        now = datetime.now().replace(hour=23, minute=59, second=59, microsecond=999999)
        dt = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) - timedelta(days=days)

        active_qs = Q(status_detail__iexact='active')
        expired_qs = Q(status_detail__iexact='expired')
        active_memberships = MembershipDefault.QS_ACTIVE()
        pending_memberships = MembershipDefault.QS_PENDING()
        memberships = MembershipDefault.objects.filter(active_qs | expired_qs)

        # Total active memberships count
        active = active_memberships.count()
        # Latest active memberships
        new = active_memberships.filter(application_approved_dt__gte=dt).count()
        # Latest pending memberships
        pending = pending_memberships.filter(create_dt__gte=dt).count()
        # Latest expired memberships
        expired = memberships.filter(expire_dt__gte=dt, expire_dt__lte=now).count()
        # Memberships that are expiring soon
        dt = now + timedelta(days=days)
        now = now.replace(hour=0, minute=0, second=0, microsecond=0)
        expiring = memberships.filter(expire_dt__gte=now,
                                      expire_dt__lte=dt).count()

        return [[active, expiring, new, pending, expired]]
    def handle(self, *args, **options):
        from tendenci.apps.memberships.models import MembershipDefault
        from tendenci.apps.invoices.models import Invoice
        from tendenci.apps.accountings.models import Acct, AcctEntry

        account_number = MembershipDefault().get_acct_number()
        acct = Acct.objects.get(account_number=account_number)

        accts_ignore = Acct.objects.filter(
            account_number__in=['220000', '120000', '106000'])
        num_trans_updated = 0

        [content_type] = ContentType.objects.filter(
            app_label='memberships', model='membershipdefault')[:1] or [None]
        if content_type:
            membership_invoices = Invoice.objects.filter(
                object_type=content_type)
            for invoice in membership_invoices:
                acct_entries = AcctEntry.objects.filter(source='invoice',
                                                        object_id=invoice.id)
                for ae in acct_entries:
                    acct_trans = ae.trans.exclude(account=acct).exclude(
                        account__in=accts_ignore)
                    if acct_trans.exists():
                        num_trans_updated += acct_trans.count()
                        acct_trans.update(account=acct)

        print('# acct_tran updated ', num_trans_updated)
Пример #3
0
    def obj_create(self, bundle, request=None, **kwargs):
        data = bundle.data

        if data['create_user']:
            print "creating user"
            user = User.objects.create(username=data['username'])
            user.set_password(data['password'])
        else:
            user = User.objects.get(username=data['username'])

        mem = MembershipDefault()
        mem.user = user
        for key in data:
            setattr(mem, key, data[key])

        mem.save()

        bundle.obj = mem

        return bundle
Пример #4
0
    def obj_create(self, bundle, request=None, **kwargs):
        data = bundle.data

        if data['create_user']:
            print "creating user"
            user = User.objects.create(username=data['username'])
            user.set_password(data['password'])
        else:
            user = User.objects.get(username=data['username'])

        mem = MembershipDefault()
        mem.user = user
        for key in data:
            setattr(mem, key, data[key])

        mem.save()

        bundle.obj = mem

        return bundle
    def get_top_corp_members(self, items):
        from tendenci.apps.memberships.models import MembershipDefault
        from tendenci.apps.corporate_memberships.models import CorpMembership

        total = MembershipDefault.QS_ACTIVE().exclude(corp_profile_id=0).count()
        corp_memberships = CorpMembership.objects.filter(status_detail='active').extra(select={
            'members': "SELECT COUNT(*) " + \
                           "FROM memberships_membershipdefault " + \
                           "WHERE memberships_membershipdefault.corp_profile_id = " + \
                               "corporate_memberships_corpmembership.corp_profile_id AND " +\
                               "memberships_membershipdefault.status_detail = 'active'"}) \
                                .order_by('-members')[:items].iterator()

        corp_mem_list = [['','',total]]
        for corp_mem in corp_memberships:
            corp_mem_list.append([corp_mem.corp_profile.name,
                                  corp_mem.get_absolute_url(),
                                  corp_mem.members])
        return corp_mem_list
 def handle(self, *args, **kwargs):
     from tendenci.apps.memberships.models import MembershipDefault
     MembershipDefault.refresh_groups()